Nagios Custom Monitoring API Plugin

Source: Internet
Author: User


Monitoring ideas: Through the URL to access the specific contents of an interface file, the regular match an interface to survive the characters must be, if there is a proof that the interface is alive, if there is no interface problem.

Nonsense not much to say, on the plugin:

#!/usr/bin/env python# -*- coding: utf-8 -*-import reimport urllibimport  sysimport getoptdef usage ():    print  "" "Usage: check_api [ -h|--help] [-u|--url url] [-s|--str string] "url: the url that you  want to check; string: the string that you want to match; " for example,#/usr/local/nagios/libexec/check_api -u  ' http://xxx.com/ch1.ashx?jsoncallback= jquery111104933076921983046_1479864376576&classid=12&systemtype=2&datatype=json&cityid=129 &videoid=36065812&pageid=1&_=1479864376577 '  -s adlist "" "    sys.exit (3) def gethtml (URL):     page = urllib.urlopen (URL)      Html = page.read ()     return htmldef getstring (Str, html):     matchobj  = re.search (Str, html, re. M)     if matchobj:        print ("GET API  ok:get %s successfully! "  % STR)         sys.exit (0)     elif  Not matchobj:        print ("get api critical:the  api was error! ")         sys.exit (2)     else:         print ("get api unknown:the api was unknow!")         sys.exit (3) Try:    options, args  = getopt.getopt (sys.argv[1:],         "Hu:S:",          "--help --url= --str=",         ) except getopt. GetopterRor:    usage ()     sys.exit (3) for name, value in  options:    if name in  ("-H",  "--help"):         usage ()     if name in  ("-U",  "--url"):         url = value    if name in  ("- S ", "--str "):        str = valuehtml =  gethtml (URL) getString (str, html)

return Result:

[Email protected] ~]#/usr/local/nagios/libexec/check_api-u ' http://xxx.com/ch1.ashx?jsoncallback= jquery111104933076921983046_1479864376576&classid=12&systemtype=2&datatype=json&cityid=129 &videoid=36065812&pageid=1&_=1479864376577 '-S adlist GET API ok:get adlist successfully!

First, the above plug-in deployment on the client, put this plug-in into/usr/local/nagios/libexec/to give executable permissions and belong to the main group, modify the/usr/local/nagios/etc/nrpe.cfg configuration file, add

Command[check_api]=/usr/local/nagios/libexec/check_api-u ' http://xxx.com/ch1.ashx?jsoncallback= jquery111104933076921983046_1479864376576&classid=12&systemtype=2&datatype=json&cityid=129 &videoid=36065812&pageid=1&_=1479864376577 ' s Adlist

Restart the Nagios client.

Second, modify the monitoring host/usr/local/nagios/etc/objects/commands.cfg file, add

Define command{command_name check_api command_line $USER 1$/check_api-u $ARG 1$-S $ARG 2$}

Modify the monitoring host/usr/local/nagios/etc/objects/services.cfg file to add

############################# #M-web-065 check_api#################################### #define  service {        host_name                m-web-065        service_ Description     check_api        check_ command           check_nrpe!check_api         max_check_attempts      5         normal_check_interval   5         retry_check_interval    2        check _period            24x7         notification_interval   10        notification_period      24x7        notification_options     u,c,r        contact_groups           yunwei}

Finally, restart Nagios to view the monitoring results

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/8A/A0/wKiom1g1YHHQfSKQAAAngyVqCUQ707.png "title=" Qq20161123172445.png "alt=" Wkiom1g1yhhqfskqaaangyvqcuq707.png "/>

This article is from "Echo Xiayun" blog, declined reprint!

Nagios Custom Monitoring API Plugin

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.