fox II/IDEC networks :: python.15 :: | Login |
{ "checks": { "cpu": { "handlers": ["email"], "command": "/etc/sensu/plugins/system/check-cpu.rb", "interval": 60, "subscribers": [ "base" ] } } }
{ "handlers": { "email": { "type": "pipe", "command": "/etc/sensu/handlers/notification/mailer.pl", "severities": ["critical", "ok"] } } }При наступлении события смены состояния чека ok<->critical выхлоп проверки в формате JSON отправится на STDIN программе mailer.pl.
$VAR1 = { 'check' => { 'status' => 2, 'handlers' => [ 'test' ], 'subscribers' => [ 'test' ], 'interval' => 60, 'history' => [ '0', '0', '0', '0', '0', '0', '0', '0',... [>>>]
s = " " + msgid + " " r = re.compile("( [a-zA-Z1-9]{8} | [a-zA-Z1-9]{20} )")
"%-20s%s" % (1, 2)
#!/usr/bin/python2 # -*- coding:utf8 -*- from ii_functions import * import os echolist=os.listdir(indexdir) for echo in echolist: print("doing "+echo) msgids=getMsgList(echo) arr=[] doubles=0 for msgid in msgids: msg=getMsg(msgid) if [msg["msg"], msg["subj"]] in arr: doubles+=1 msgids.remove(msgid) print msgid else: arr.append([msg["msg"], msg["subj"]]) if doubles>0: print("doubles: "+str(doubles)) open("echo_new/"+echo, "w").write("\n".join(msgids)+"\n")
#!/usr/bin/python # -*- coding: utf-8 -*- from sensu_plugin import SensuPluginCheck from os import listdir from os.path import isfile,join class CoolCheck(SensuPluginCheck): def setup(self): self.parser.add_argument( '-w', '--warning', required=True, type=int, help='Integer warning level to output' ) self.parser.add_argument( '-c', '--critical', required=True, type=int, help='Integer critical level to output' ) self.parser.add_argument( '-d', '--directory', required=True, type=str, help='Path to directory' ) def run(self): self.check_name('my_cool_check') dir = self.options.directory onlyfiles = [ f for f in listdir(dir) if isfile( join(dir, f) ) ] size = len(onlyfiles) if size < self.options.warning: self.ok() # Exit code 0 elif size >= self.options.warning and size < self.options.critical: self.warning('Files count ' + str(size)) # Exit code 1 elif size >= self.options.critical: self.critical('Files count ' + str(size)) # Exit code 2 else: self.unknown('Unknown error') if __name__ == "__main__": f = CoolCheck()
#!/usr/bin/python2 # -*- coding:utf8 -*- from ii_functions import * import os echolist=os.listdir(indexdir) for echo in echolist: print("doing "+echo) msgids=getMsgList(echo) msgs={} for msgid in msgids: msg=getMsg(msgid) msg["time"]=int(msg["time"]) msgs[msgid]=msg def sortTime(msgid): return msgs[msgid].get("time") msgids.sort(key=sortTime) open("echo_new/"+echo, "w").write("\n".join(msgids)+"\n")