To demonstrate how you can use our new API to leverage deeper integration with your internal monitoring tools, we’re going to guide you through an example that connects Nagios (a ubiquitous open source monitoring tool) with BrowserMob’s web site monitoring service.

Getting it all setup:

Since this is intended to be a quick how-to, we’re going to assume that you already have a working Nagios installation behind your firewall and an active monitoring job with BrowserMob. Here at the BMob we eat our own dog food, utilizing our own monitoring service to monitor BrowserMob.com. For this example, we’ll use a monitoring job called “BMOB” for our Nagios integration.

What you will need:

  1. API Key & API Secret. Log on to browsermob.com with your account and under Home > My Profile you will find your API key and secret.
  2. CLI BrowserMob API tool. Download our nifty API command line tool from http://github.com/rferreira/bmob-python
  3. Nagios 3.06. We have it installed on Ubuntu Jaunty for this example.
  4. jsonpretty. This just makes JSON strings human-readable in the CLI. Get it here: http://github.com/nicksieger/jsonpretty

Getting to know your monitoring job:

Before we can actually wire anything into Nagios we need to find out the internal id of a monitoring job. In the BrowserMob web interface monitoring jobs have friendly names like “BMOB”, but internally they are referenced by a unique id such as “fe33b13dc0764588b5eabf747a96a48b”.

You will need the monitoring job’s unique id. You can get it by running the following query (replacing the credentials with your own):

$ ./bmob.py -c XXX:XXX http://browsermob.com/a/m/all | jsonpretty
[
{
"browsers": [
"FF3"
],
"name": "BMOB",
"lastBilled": null,
"alertEmail": "support@browsermob.com",
"preferenceId": "7ea6d3b47c8c4a1c8d30db7fef9d5fd1",
"lastRun": 1273007522255,
"deleted": false,
"enabled": true,
"id": "fe33b13dc0764588b5eabf747a96a48b",
"lastUpdated": 1273005121243,
"frequency": 15,
"locations": [
"DALLAS",
"SING",
"AMS",
"NY",
"DC",
"DUBLIN",
"SF"
],
"scriptId": "21312a2da1834f2aa02db73f32037619",
"accountId": 2,
"email": "raf@browsermob.com"
}
]

Look for the “id” property in the JSON response.

Wiring it all up:

Now we need to write a wrapper script to query and parse the API results. Create a file called “check_bmob.sh” with the following contents:

#!/usr/bin/env bash
 
# RETURN CODES:
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
 
WARNING_T=2000
CRITICAL_T=5000
 
ID="fe33b13dc0764588b5eabf747a96a48b"
 
# dates
START=$(date -u  --date="5 mins ago" +%s)000
END=$(date -u  +%s)000
RESP=$(/opt/bmob-python/bmob.py -d metric=responseTime,start=$START,end=$END,resolution=hour –c XXX:XXX http://browsermob.com/a/m/$ID | tr "," "\n" | grep responseTime | awk -F ":" '{print $2}')
 
for t in $RESP
do
   if [ $t -gt $CRITICAL_T ]
      then
         echo $t
         exit $CRITICAL
   elif [ $t -gt $WARNING_T ]
      then
         echo $t
         exit $WARNING
   fi
done
 
exit 0

What this script will do is look up the response time for the last 5 minutes and trigger an alert if the response time is greater than the threshold for WARNING_T or CRITICAL_T.

Now, we just need to tell Nagios to use it; the sample config below should do the trick:

# defining the command
define command {
    command_name    check_bmob
    command_line    /usr/lib/nagios/plugins/check_bmob.sh
}
 
define hostgroup {
    hostgroup_name website
    alias web site
}
 
define host {
    host_name browsermob.com
    check_command check_http
    alias login-check
    use generic-host
}
 
define service {
    hostgroup_name                  website
    service_description             response_time
    check_command                   check_bmob
    host_name                       browsermob.com
    use generic-service
}

Please keep in mind that Nagios’ configuration files can be–and usually are–fairly complex. The example above is purposely simple and may need to be modified to work in your environment.

If everything works as planned you should be able to log in to the Nagios web interface and see:

Pudding

Pudding

Official BrowserMob API documentation:

http://cdn.browsermob.com/api.html

3 Responses to “Integrating BrowserMob with Nagios”

  1. [...] Integrating BrowserMob with Nagios · The BrowserMob Blog – September 2nd %(postalicious-tags)( tags: browsermob monitoring nagios howto guide )% [...]

  2. often duplicated, but yet to? be equalled. I still adore this years later

  3. How Can , I sign off owershiper For Mobile Home,But yet…?

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

 

© 2012 The BrowserMob Blog Suffusion theme by Sayontan Sinha