1. Nagios Installation
Yum Install-y nagios.i686
Yum Install-y nagios-plugins-all.i686
After installation, an external configuration file will be generated in the Apache profile directory/etc/httpd/conf.d/nagios.conf
Service httpd Start
Service Nagios Start
Default User nagiosadmin password nagiosadmin
2. configuration File Generator
Django Pre-collection host information code
Group on Nagios
Vim gen.py
1 #!/usr/bin/env python2 3 ImportOS4 ImportUrllib,urllib25 ImportJSON6 7Cur_dir = Os.path.dirname (__file__)8Conf_dir = Os.path.join (Os.path.abspath (Cur_dir),'hosts')9 Tenhost_temp="""define host{ One Use linux-server A host_name% (hostname) s - alias% (hostname) s - address% (IP) s the } - """ -hostgroup_temp="""define hostgroup{ - hostgroup_name% (groupname) s + alias% (groupname) s - Members % (members) s + } A """ at defInitdir (): - if notos.path.exists (conf_dir): - Os.mkdir (Conf_dir) - - defgetData (): -URL ='http://192.168.1.120:8000/hostinfo/getjson/' inreq =urllib2.urlopen (URL) -data =json.loads (Req.read ()) to returnData + - defwriteconf (f,data): theWith open (F,'W') as FD: * fd.write (data) $ Panax Notoginseng defparsedata (data): -host_conf ="' thehostgroup_conf ="' + forHginchData: AGroupName = hg['GroupName'] theMembers = [] + forHinchhg[' Members']: -hostname = h['hostname'] $ Members.append (hostname) $host_conf + = host_temp%h -hostgroup_conf + = hostgroup_temp% {'GroupName': GroupName,' Members':','. Join (members)} -fp_hostconf = Os.path.join (Conf_dir,'hosts.cfg') thefp_hostgroupconf = Os.path.join (Conf_dir,'hostgroup.cfg') - writeconf (fp_hostconf,host_conf)Wuyi writeconf (fp_hostgroupconf,hostgroup_conf) the - Wu if __name__=='__main__': - Initdir () Aboutdata =GetData () $Parsedata (data)
gen.py
Synchronizing Profiles sync_gen.sh
1 #!/bin/bash2 3Cur= ' DirName $`4Cd$cur5 python gen.py6Md5= ' Find hosts/-type f-exec md5sum {} \;|md5sum '7cd/etc/nagios/CONF.D8Conf_md5= ' Find hosts/-type f-exec md5sum {} \;|md5sum '9 if["$MD 5"!="$conf _md5"];thenTenCD- OneCP-RP hosts//etc/nagios/CONF.D A/etc/init.d/Nagios Restart -Fi
Python-django monitoring System two times development Nagios