码迷,mamicode.com
首页 > 移动开发 > 详细

python写简单的nagios主机配置文件

时间:2015-03-19 16:41:22      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

__author__ = ‘Administrator‘
import sys,os
dir_cfg="./"
#file=sys.argv[1]
#hostname=sys.argv[2]
#app=sys.argv[3]
#ip=sys.argv[4]
#port=sys.argv[5]

def test(file,hostname,app,ip,port):
    filepath=dir_cfg+file
    if os.path.exists(filepath):
        try:
            wf=open(filepath,‘a‘)
            wf.write(data_02%(hostname,app,port))
            wf.close()
        except:
            print(‘Write file fail2!‘)
            wf.close()
    else:
        try:
            wf=open(filepath,‘w‘)
            wf.write(data_01%(hostname,hostname,ip,hostname,app,port))
            wf.close()
        except:
            print(‘Write file fail!‘)
            wf.close()

data_01=‘‘‘
define host{
        use                     generic-host
        host_name               %s
        alias                   %s
        address                 %s
        }

define service {
        use                             generic-service
        host_name                       %s
        service_description             %s
        check_command                   check_tcp!%s
}
‘‘‘
data_02=‘‘‘
define service {
        use                             generic-service
        host_name                       %s
        service_description             %s
        check_command                   check_tcp!%s
}
‘‘‘
#print("%-40s %-10s"%(‘7899999999999999999999‘,‘hhh‘))

if __name__ == "__main__":
    test(‘kkk.cfg‘,‘kkk‘,‘SSH‘,‘127.0.0.1‘,‘80‘)


python写简单的nagios主机配置文件

标签:

原文地址:http://my.oschina.net/jk409/blog/389008

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!