python-Django監控系統二次開發Nagios

來源:互聯網
上載者:User

標籤:

1、Nagios安裝

yum install -y nagios.i686

yum install -y nagios-plugins-all.i686

安裝完後會在apache的設定檔目錄下/etc/httpd/conf.d/產生一個外部的設定檔nagios.conf

service httpd start

service nagios start

default user nagiosadmin password nagiosadmin

2.設定檔產生器

Django前期的收集主機資訊代碼

在nagios上分組

vim gen.py

 1 #!/usr/bin/env python 2  3 import os 4 import urllib,urllib2 5 import json 6  7 CUR_DIR = os.path.dirname(__file__) 8 CONF_DIR = os.path.join(os.path.abspath(CUR_DIR),‘hosts‘) 9 10 HOST_TEMP="""define host{11                 use             linux-server12                 host_name       %(hostname)s13                 alias           %(hostname)s14                 address         %(ip)s15                 }16         """17 HOSTGROUP_TEMP="""define hostgroup{18         hostgroup_name  %(groupname)s19         alias           %(groupname)s20         members         %(members)s21         }22     """23 def initDir():24     if not os.path.exists(CONF_DIR):25         os.mkdir(CONF_DIR)26 27 def getData():28     url = ‘http://192.168.1.120:8000/hostinfo/getjson/‘29         req = urllib2.urlopen(url)30         data = json.loads(req.read())31     return data32 33 def writeConf(f,data):34         with open(f,‘w‘) as fd:35                 fd.write(data)36 37 def parseData(data):38     host_conf = ‘‘39     hostgroup_conf = ‘‘40     for hg in data:41         groupname = hg[‘groupname‘]42         members = []43         for h in hg[‘members‘]:44             hostname = h[‘hostname‘]45             members.append(hostname)46             host_conf += HOST_TEMP % h47         hostgroup_conf += HOSTGROUP_TEMP % {‘groupname‘:groupname, ‘members‘:‘,‘.join(members)}48     fp_hostconf = os.path.join(CONF_DIR,‘hosts.cfg‘)49     fp_hostgroupconf = os.path.join(CONF_DIR,‘hostgroup.cfg‘)50     writeConf(fp_hostconf,host_conf)51     writeConf(fp_hostgroupconf,hostgroup_conf)52 53 54 if __name__ == ‘__main__‘:55     initDir()56     data = getData()57     parseData(data)
gen.py

 同步設定檔sync_gen.sh

 1 #!/bin/bash 2  3 cur=`dirname $0` 4 cd $cur 5 python gen.py 6 md5=`find hosts/ -type f -exec md5sum {} \;|md5sum` 7 cd /etc/nagios/conf.d 8 conf_md5=`find hosts/ -type f -exec md5sum {} \;|md5sum` 9 if [ "$md5" != "$conf_md5" ];then10     cd -11     cp -rp hosts/ /etc/nagios/conf.d12     /etc/init.d/nagios restart13 fi

 

python-Django監控系統二次開發Nagios

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.