#!/usr/bin/env python # Copyright (C) 2007 Platform Computing Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # # # import os import string class MyRCScript: def configNRPE(self): self.osArch = os.uname()[4] if self.osArch == "x86_64": self.osArch = "lib64" else: self.osArch = "lib" self.generate() def generate(self): profile = '/etc/profile.nii' nagiosServers = [] if not os.path.exists(profile): return False fp = open(profile, 'r') lines = fp.readlines() fp.close() for line in lines: if line[0] == "#" or line.isspace(): continue try: key,val = string.split(line, "=", 1) except: continue val = val.rstrip() val = val.strip('"') if key == "export NagiosServers": nagiosServers = val.split(' ') break fptr = open("/etc/nagios/nrpe.cfg", 'r+') data = [] newdata = [] data = fptr.readlines() for line in data: if line.find("check_disk1") > 0: newdata.append("command[check_disk]=/usr/%s/nagios/plugins/check_disk -w 20%% -c 10%% -p /\n" % self.osArch) continue if line.find("check_disk2") > 0: newdata.append("command[check_mem]=/usr/%s/nagios/plugins/check_mem -f -w 20 -c 10\n" % self.osArch) newdata.append("command[check_swap]=/usr/%s/nagios/plugins/check_swap -w 20%%%% -c 10%%%%\n" % self.osArch) continue if line.find("check_total_procs") > 0 and line.find("RSZT") < 0: newdata.append("command[check_total_procs]=/usr/%s/nagios/plugins/check_procs -w 150 -c 200 -s RSZT" % self.osArch) continue newdata.append(line) fptr.seek(0, 0) fptr.writelines(newdata) fptr.close() fptr = open("/etc/nagios/nrpe.cfg", 'w') for line in newdata: if line.find("allowed_hosts") >= 0: newline = "allowed_hosts=" + ",".join(nagiosServers) + "\n" fptr.write(newline) else: fptr.write(line) fptr.close() # FIXME: We have to call this plugin as a script when installing the nagios kit because we dont have any genconfig scripts. So to mimic this, call this # as a script instead. if __name__ == "__main__": myApp = MyRCScript() myApp.configNRPE() try: os.unlink("/etc/rc.kusu.d/S16-nrpeconfig") except: pass