Python-django monitoring System two times development Nagios

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.