Recently I created a new nagios plugin which check the no. of instances attached in ELB (Elastic Load Balancer) . Here we are talking about ELB in AWS (Amazon Web Service) Cloud. Elastic Load Balancing automatically distributes incoming application traffic across multiple Amazon EC2 instances in the cloud.
Details of check_ELBinstance nagios plugin
Requirement : To check no. of desired instances attached in ELB. If no. of instances count does’nt match then send the alert (Critical)
By this way we can monitor, if desired number of instances in ELB increased or decreased in number.
Scripting : Bash scripting is used for creating the check_ELBinstance nagios plugin.
Install aws command line interface on Nagios Server. It requires Python 2.6.5 or higher.
Run the below given command –
pip install awscli
You can download this plugin and do changes as per your requirement.
I have saved this nagios plugin in github. The given below is the link
In either way you can create a file check_ELBinstance.sh in nagios plugin directory on Nagios Server. And copy paste the below given contents.
#!/bin/bash # # Author : Sharad Kumar Chhetri # Date Of Creation : 1-Nov-2014 # Version : 1.0 # Description : It checks the no. of instances available in ELB . When the instances count do not matches as per desire value it will send alert. # Blog : https://sharadchhetri.com # ### Supportive URL : http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html ### export AWS_ACCESS_KEY_ID="XXXXXXXXXXXXXXXXXXX" export AWS_SECRET_ACCESS_KEY="YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" #### For getting Region infromation,Reference URL: http://docs.aws.amazon.com/general/latest/gr/rande.html REGION=us-west-1 ## In ELB_NAME - Provide name of ELB ELB_NAME=ProductionELB ## In INSTANCE_COUNT give the value of desired number of Instances should be in ELB INSTANCE_COUNT=4 ## The ELB_INSTANCE_COUNT gives output of no. of instances attached in ELB ELB_INSTANCE_COUNT=$(aws --region $REGION elb describe-load-balancers --load-balancer-names $ELB_NAME --output text|grep INSTANCES|wc -l) if [ "$ELB_INSTANCE_COUNT" == "$INSTANCE_COUNT" ] then echo "OK: Total no. of instances $ELB_INSTANCE_COUNT found in ELB $ELB_NAME" exit 0 else if [ "$ELB_INSTANCE_COUNT" != "$INSTANCE_COUNT" ] then echo "CRIT: Number of instances in ELB $ELB_NAME do not matches with desired value" exit 2 fi fi
Nishith N.Vyas says
Can we monitor AWS ALB using this command? My command output is as mentioned below.
An error occurred (LoadBalancerNotFound) when calling the DescribeLoadBalancers operation: There is no ACTIVE Load Balancer named ‘test-alb’
CRIT: Number of instances in ELB test-alb is 0,which do’nt matches with desired value i.e 2
The AWS Access Key & Secret Access Keys are okay.
Benjamin John says
This one worked great. Do you have any other Nagios-AWS plugins?
Sharad Chhetri says
You can find here –
Nishith N.Vyas says
Have you configured ELB/CLB or ALB?
showing ok on the command line but showing critical on nagios we interface ..