#!/usr/bin/env python
"""Logger - logs results of fs size probes into a log file.
Format is:
Date | Probe | Alert Level
Message
"""
import time
# We need to specify thresholds - this basically sets the alert level. The date and probe name and even the message will be the same. However, the threshold will determine the severity.
# Silly Temp Values
filelist = ["ok", "hrm", "panic"]
silly = {'ok':60, 'hrm':600, 'panic':1100}
# Global Defines
TIMESTAMP = time.asctime(time.localtime())
# Let's set some threshold values:
BI_INFO = 500 * (1024*1024)
BI_WARN = 1000 * (1024*1024)
# Utility functions
def sizeCheck(f):
#size = os.path.getsize(file)
size = silly[f]
if size < BI_INFO:
return ("INFO", size)
elif size < BI_WARN:
return ("WARN", size)
else: return ("CRIT", size)
def biProbe():
PROBE = "Bi File Check"
for f in filelist:
LEVEL, size = sizeCheck(f)
MESSAGE = "%s : %s bytes" %(f, size)
print TIMESTAMP + " | " + PROBE + " | " + LEVEL
print MESSAGE
biProbe()
---------------------
bash-3.1$ python logger
Thu Sep 21 22:54:39 2006 | Bi File Check | INFO
ok : 60 bytes
Thu Sep 21 22:54:39 2006 | Bi File Check | INFO
hrm : 600 bytes
Thu Sep 21 22:54:39 2006 | Bi File Check | INFO
panic : 1100 bytes
-----
Should give "WARN" and "CRIT" for the hrm and panic data.