Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_ec2_instance.php

Current Version
0.4
Last Release Date
2012-04-30
Compatible With
  • Nagios 3.x
Owner
License
GPL
Hits
69699
Files:
FileDescription
check_ec2_instance.phpcheck_ec2_instance.php
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
Uses the AWS PHP SDK to query EC2 instance state.

Requires SDK installed somewhere in the include path (ubuntu in my case /usr/share/php) and requires authentication keys to be set in SDK.
Expects to receive the instance id passed on the command line.

I’ve created hosts with the instance-id as the hostname, it will return warning if instance is in pending state, and critical if state is stopped or stopping.
Also returns warning if instance has been recently started (to remind me to rebind the elastic ip)

If you notice script returning “STATE UNKNOWN TO THIS SCRIPT”, chances are it’s a 272 instance code, which looks like a known issue, couldn’t find a fix, but aws forums recommend restarting the instance.

Script prints the received instance code with the message it provides to nagios.

Easily changed values are listed at the top, min_uptime for controlling how long instance needs to be up to not trigger a warning and messages passed to nagios for various conditions.


Currently running and tested with Nagios 3.x.

cc


Reviews (1)
Took a little while to get this working cos I'm not a developer.. so here are a few tips to get the SDK working

This needs version 1 of the AWS SDK for PHP
http://aws.amazon.com/sdkforphp/

As stated, you punch in your AWS credentials into a file called config.inc.php
Good idea to test the sdk with the sample script that comes with the SDK called "cli-s3_get_urls_for_uploads.php"

If you are behind a proxy, you can specify the proxy in sdk.class.php in the line "public proxy = "
eg., public $proxy = "http://username:password@proxy:8080";

Nb. I hit errors with proxies until I found out that proxy support was fixed in a recent commit:
https://github.com/amazonwebservices/aws-sdk-for-php/pull/49#commits-pushed-eb922ad



The AWS SDK for PHP defaults to the US East Region. (ec2.us-east-1.amazonaws.com)
You need to set the region if your instances are in a different region.
eg., if you were in Asia Pacific Singapore region..

Add a line after "$ec2 = new AmazonEC2();"
$ec2->set_hostname('ec2.ap-southeast-1.amazonaws.com');


For a list of hosts and for the regions, refer to this...
http://docs.amazonwebservices.com/general/latest/gr/rande.html#ec2_region