witre nagios plugin with python
来源:互联网 发布:mtv电子相册制作软件 编辑:程序博客网 时间:2024/05/18 02:04
Our Solarwinds Network Performance Monitor has a problem rendering custom reports on occasion. For something like that, there isn't an existing plugin for Nagios. Writing these plugins is easy. All there is to it is exit statuses. After reading this, you should have an idea of how to write a Nagios plugin for a variety of web applications.
1 2 3 4 5 6 7 8 91011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
#!/usr/bin/env pythonfrom mechanize import Browserfrom optparse import OptionParser# Exit statuses recognized by NagiosUNKNOWN = -1OK = 0WARNING = 1CRITICAL = 2def open_url(br, url): """Use a given mechanize.Browser to open url. If an exception is raised, then exit with CRITICAL status for Nagios. """ try: response = br.open(url) except Exception, e: # Catching all exceptions is usually a bad idea. We want to catch # them all to report to Nagios here. print 'CRITICAL - Could not reach page at %s: %s' % (url, e) raise SystemExit, CRITICAL return response# I'm going to be using optparse.OptionParser from now on. It makes# command-line args a breeze.parser = OptionParser()parser.add_option('-H', '--hostname', dest='hostname')parser.add_option('-u', '--username', dest='username')parser.add_option('-p', '--password', dest='password')parser.add_option('-r', '--report_url', dest='url', help="""Path to report relative to root, like /NetPerfMon/Report.asp?Report=Hostname+__+IPs""")parser.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False)parser.add_option('-q', '--quiet', dest='verbose', action='store_false')options, args = parser.parse_args()# Check for required optionsfor option in ('hostname', 'username', 'password', 'url'): if not getattr(options, option): print 'CRITICAL - %s not specified' % option.capitalize() raise SystemExit, CRITICAL# Go to the report and get a login pagebr = Browser()report_url = 'https://%s%s' % (options.hostname, options.url)open_url(br, report_url)br.select_form('aspnetForm')# Solarwinds has interesting field names# Maybe something with asp.netbr['ctl00$ContentPlaceHolder1$Username'] = options.usernamebr['ctl00$ContentPlaceHolder1$Password'] = options.password# Attempt to login. If we can't, tell Nagios.try: report = br.submit()except Exception, e: print 'CRITICAL - Error logging in: e' % e raise SystemExit, CRITICALreport_html = report.read()# class=Property occurs in every cell in a Solarwinds report. If it's not# there, something is wrong.if 'class=Property' not in report_html: print 'CRITICAL - Report at %s is down' % report_url raise SystemExit, CRITICAL# If we got this far, let's tell Nagios the report is okay.print 'OK - Report at %s is up' % report_urlraise SystemExit, OK
To use our plugin, we need to do a bit of Nagios configuration. First, we need to define a command.
define command{ command_name check_npm_reports command_line /usr/local/bin/reportmonitor.py -H $HOSTADDRESS$ $ARG1$}
After that, we define a service.
define service{ use generic-service host_name solarwinds-server service_description Solarwinds reports check_command check_npm_reports!-u nagios -p some_password -r '/NetPerfMon/Report.asp?Report=Hostname+__+IPs'}
- witre nagios plugin with python
- Remotely monitor servers with the Nagios check_by_ssh plugin
- Nagios Plugin API
- nagios-plugin 编译
- Eclipse for Python with plugin not online
- Bash Scripting and Nagios plugin
- [原创] Nagios install Plugin check_iostat
- Best Nagios plugin for SMARTd / smartmontools
- nagios-plugin-1.4.16 编译备忘
- nagios-plugin和nrpe快速部署办法
- nagios python template
- manve with cxf plugin
- Building a Monitoring Infrastructure with Nagios
- writing GIMP plugin with OpenCV
- Fck with Jquery Form Plugin
- Centreon+Nagios实战第三篇——监控端安装Nagios-plugin
- nagios
- nagios
- zoj 1008 DFS
- 安卓手机共享上网
- 马上就要上班了
- 偵測 Linux 上面的流量 【鸟哥】
- ON_COMMAND_RANGE 多个按钮响应一个函数
- witre nagios plugin with python
- nagios python template
- 使用Eclipse构建Maven的SpringMVC项目
- sscanf切割字符串
- Algorithm Practice for 1579
- [Android]酷派8150手机安卓2.3.7系统不能发现Adhoc网络
- [gpu pro]《正当防卫2》渲染技术
- BIT 1015 Edit Distance
- Erlang实现handlersocket客户端