• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

check_ELBinstance : Nagios Plugin to check instances attached with ELB

November 27, 2014 by Sharad Chhetri

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.

Prerequisite

Install aws command line interface on Nagios Server. It requires Python 2.6.5 or higher.
Run the below given command –

pip install awscli

Download check_ELBinstance

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

https://github.com/sharadchhetri/Nagios/blob/master/check_ELBinstance.sh

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

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. check_openerp nagios plugin for openerp service check
  2. Nagios Plugin : check ssl certificate expiry date
  3. Nagios monitoring on AWS Autoscaling group instances
  4. Xen Server License Nagios Plugin (bash script)
  5. Nagios plugin check_mailfromd bash script
  6. Protect from SSL Drown Attack in AWS ELB, Apache and Nginx
  7. Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!
  8. How to Check UUID of Disk Partition
  9. Set group password,its use and check which group after newgrp command in linux
  10. 6 df Command Examples To Check Mounted Filesystem On Linux

Filed Under: Monitoring Server Tagged With: Nagios

Reader Interactions

Comments

  1. Nishith N.Vyas says

    June 25, 2021 at 11:18 am

    Can we monitor AWS ALB using this command? My command output is as mentioned below.

    ./check_ELBinstance.sh

    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.

  2. Benjamin John says

    July 27, 2017 at 6:46 pm

    This one worked great. Do you have any other Nagios-AWS plugins?

    • Sharad Chhetri says

      August 3, 2017 at 2:20 am

      Hi Benjamin,

      You can find here –
      https://github.com/sharadchhetri/Nagios
      https://exchange.nagios.org/directory/Owner/sharadkchhetri/1

      Regards
      Sharad

    • Nishith N.Vyas says

      June 25, 2021 at 11:19 am

      Have you configured ELB/CLB or ALB?

  3. prem says

    January 11, 2017 at 6:18 pm

    showing ok on the command line but showing critical on nagios we interface ..
    please help

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

Non interactive ,without typing password do ssh to Server : By sshpass

This kernel requires an x86-64 CPU but only detected an i686 CPU

How to zip the directory in linux with command line

How to install pam_mysql in CentOS or Red Hat

How to protect from port scanning and smurf attack in Linux Server by iptables

linux release renew dhcp assigned ip address

configure: error: C++ compiler cannot create executables

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy