• Monitor Remote Windows Machine Using Nagios on Linux

    Monitoring private services or attributes of a Windows machine requires that you install an agent on it. This agent acts as a proxy between the Nagios plugin that does the monitoring and the actual service or attribute of the Windows machine. Without installing an agent on the Windows box, Nagios would be unable to monitor private services or attributes of the Windows box.

    For this example, we will be installing the NSClient++ addon on the Windows machine and using the check_nt plugin to communicate with the NSClient++ addon. The check_nt plugin should already be installed on the Nagios server

    Configurations in Windows Server

    1) Install NSClient++ on the remote windows server

    http://sourceforge.net/projects/nscplus/  ( only for 64bit processors )

    ( 32 bit version can be downloaded from : http://www.nsclient.org/nscp/downloads )

    In this new version , we can very easily install and configure the NSClient.
    While installaling in the 4th step it will ask for the allowed hosts, here you can sepecify the nagios server. No need to set the password.

    Once the installation is completed then the service will start automatically.

    2) Confirm port=12489 is uncommented in NSC.in )

    ( Edit the C:\Program Files\NSClient++\NSC.ini file and uncomment the port# under [NSClient] section)

    3) Open the services manager and make sure the NSClientpp service is allowed to interact with the desktop (see the ‘Log On’ tab of the services manager). If it isn’t already allowed to interact with the desktop, check the box to allow it to.

    ( Go to Control Panel -> Administrative Tools -> Services. Double click on the “NSClientpp” service and select the check-box that says “Allow service to interact with desktop” )

    Configurations in Nagios Server

    1) Confirm check_nt command is enabled in /usr/local/nagios/etc/objects/commands.cfg

    # ‘check_nt’ command definition
    define command{
    command_name    check_nt
    command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$

    2) create new services.cfg file for the windows server .

    vi  /usr/local/nagios/etc/objects/clients/windows-server.cfg

    # Define the host

    define host{
    host_name               windows-adminlogs.info
    alias                   remote-windows-server
    check_command           check-host-alive
    contact_groups          admins
    use                     generic-host

    # Define the services

    define service{
    use                     generic-service
    host_name               windows-adminlogs.info
    service_description     Uptime
    contact_groups          admins
    check_command           check_nt!UPTIME

    define service{
    use                     generic-service
    host_name               windows-adminlogs.info
    service_description     CPU Load
    check_command           check_nt!CPULOAD!-l 5,80,90

    define service{
    use                     generic-service
    host_name               windows-adminlogs.info
    service_description     Memory Usage
    check_command           check_nt!MEMUSE!-w 80 -c 90

    define service{
    use                     generic-service
    host_name               windows-adminlogs.info
    service_description     C:\ Drive Space
    check_command           check_nt!USEDDISKSPACE!-l c -w 80 -c 90

    define service{
    use                     generic-service
    host_name               windows-adminlogs.info
    service_description     D:\ Drive Space
    contact_groups          admins
    check_command           check_nt!USEDDISKSPACE!-l c -w 80 -c 90

    3) Add the new configuration file in nagios configuration

    vi /usr/local/nagios/etc/nagios.cfg

    4) Verify the configurations and syntax are correct

    nagios -v /usr/local/nagios/etc/nagios.cfg

    5) Restart nagios

    Yes, now you can monitor your windows servers from linux

    More nagios docs here : Adminlogs Nagios Docs

  • Nagios sms alert configuration

    Nagios SMS Alert Configuration

    Scenario : Migration of local nagios server to amazon EC2

    My current setup was a local nagios server with a gsm modem connected on it for sending sms alerts.

    But in the new setup , I need to set up nagios server remotely ( amazon ).  All other parts we did just like the existing server except sms alert configuration.

    To setup sms alert , we should use a third party to send sms through their servers.  We signed up with www.clickatell.com sms gateway service, its cheap and reliable.

    Once you start an account with them , they will provide login details with a client id. To use their sms gate way service , we need to create appropriate API

    1) Create an API in clicatel gateway service

    They are providing lots of methods to send sms through their gateway like https, smtp etc. I selected http and create the http API . Its pretty easy with their panel.

    2)  Define New Command in commands.cfg

    # host-notify-by-sms command definition
     define command{
     command_name host-notify-by-sms
     command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$ \nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | wget "http://api.clickatell.com/http/sendmsg?user=clicatel-user-name&password=password&&api_id=XXXXX&to=$CONTACTEMAIL$&text='** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ @ $LONGDATETIME$ **'"

    # service-notify-by-sms command definition

    define command{
     command_name service-notify-by-sms
     command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$ \nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | wget "http://api.clickatell.com/http/sendmsg?user=clickatel-user-name&password=password&api_id=XXXXX&to=$CONTACTEMAIL$&text='** $NOTIFICATIONTYPE$ Service Alert: $SERVICEDESC$ on $HOSTNAME$ State: $SERVICESTATE$ @ $LONGDATETIME$ **'"

    3) Use new command in contacts.cfg

    define contact{
    contact_name                    admin
    alias                                  Adminlogs
    service_notification_period     24×7
    host_notification_period        24×7
    service_notification_options    c,r
    host_notification_options         d,r
    service_notification_commands   service-notify-by-sms
    host_notification_commands      host-notify-by-sms
    email                           651234567

    4) Verify nagios configuaration

    nagios -v /etc/nagios/nagios.cfg

    5) Restart nagios

    6) Test and Verify new command

    wget "http://api.clickatell.com/http/sendmsg?user=clicatel-user-name&password=password&&api_id=XXXXX&to= 651234567&text=' *** Welcome to adminlogs.info ***'"

    If you are getting the message to your number then log out and we can go for a tea 😀  …Yes , You completed the sms alert configuration successfully ..Nagios Rocks !!!!! 😉

    From the Clickatel panel , you will get the complete report about the nagios alerts sent via their gateway

  • Nagios jabber Configuration

    Nagios jabber notification using XMPP protocol and SASL PLAIN authentication

    Nagios can be configured to send notifications by various means, including Jabber, which these days includes Google talk’s XMPP service.


    1)  Create notify_via_jabber plugin


    #!/usr/bin/perl -w
    # script for nagios notify via Jabber / Google Talk Instant Messaging
    #   using XMPP protocol and SASL PLAIN authentication.
    # author: Andrew Elwell <[email protected]>
    # based on work by Thus0 <[email protected]> and  David Cox
    # released under the terms of the GNU General Public License v2
    # Copyright 2007 Andrew Elwell.
    use strict;
    use Net::XMPP;
    ## Configuration
    my $username = "your.google.username";
    my $password = "your.google.password";
    my $resource = "nagios";
    ## End of configuration
    my $len = scalar @ARGV;
    if ($len ne 2) {
       die "Usage...\n $0 [jabberid] [message]\n";
    my @field=split(/,/,$ARGV[0]);
    # Google Talk & Jabber parameters :
    my $hostname = 'talk.google.com';
    my $port = 5222;
    my $componentname = 'gmail.com';
    my $connectiontype = 'tcpip';
    my $tls = 1;
    my $Connection = new Net::XMPP::Client();
    # Connect to talk.google.com
    my $status = $Connection->Connect(
           hostname => $hostname, port => $port,
           componentname => $componentname,
           connectiontype => $connectiontype, tls => $tls);
    if (!(defined($status))) {
       print "ERROR:  XMPP connection failed.\n";
       print "        ($!)\n";
    # Change hostname
    my $sid = $Connection->{SESSION}->{id};
    $Connection->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname;
    # Authenticate
    my @result = $Connection->AuthSend(
           username => $username, password => $password,
           resource => $resource);
    if ($result[0] ne "ok") {
       print "ERROR: Authorization failed: $result[0] - $result[1]\n";
    # Send messages
    foreach ( @field ) {
            to       => "$_\@$componentname",
            resource => $resource,
            subject  => "Notification",
            type     => "chat",
            body     => $ARGV[1]);



    2) We need to configure new command in command.cfg as follows

    #Host Notifications

    define command{
     command_name host-notify-by-jabber
     command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$ \nState: $HOSTSTATE$\n Address: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/lib/nagios/plugins/notify_via_jabber $CONTACTPAGER$ "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **"

    # Service notifications

    define command{
     command_name notify-by-jabber
     command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$ \nState: $HOSTSTATE$\n Address: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/lib/nagios/plugins/notify_via_jabber $CONTACTPAGER$ "** $NOTIFICATIONTYPE$ Service Alert: $SERVICEDESC$ on $HOSTNAME$ State: $SERVICESTATE$ **"


    3)  Verify the new configuration

    nagios -v /etc/nagios/nagios.cfg


    4)  Restart Nagios

    If everything is configured fine then nagios will alert you about host/service status to the given address.





  • Bandwidth monitoring using nagios

    About : –

    check_traffic is a very nice tool to alert the server bandwidth usage in linux servers. Its very easy to configure but very powerful.

    Download & Install plugin  :-


    $ wget check_tcptraffic-2.2.3.tar.gz
    $ tar -zxf check_tcptraffic-2.2.3.tar.gz
    $ cd check_tcptraffic-2.2.3
    In the source directory run:
    $ perl Makefile.PL
    $ make
    $ make install

    Client server nrpe.cfg

    command[check_traffic]=/usr/lib64/nagios/plugins/check_tcptraffic-2.2.3/check_tcptraffic  -c <value>  -w <value > -i eth0 -s 100

    $ /etc/init.d/nrpe restart

    Nagios Server/Services config

    define service {
    service_description         Server Bandwidth Usage
    hosts                           adminlogs.info
    normal_check_interval     5
    retry_check_interval       1
    contact_groups              admins
    notification_interval        60
    notification_period          wakinghours
    check_command             nrpe_check!check_traffic
    use                              generic-service

    Verify the nagios conf and restart nagios

    $ nagios -v /etc/nagios/nagios.cfg

    $ /etc/init.d/nagios restart

    Yes , that’s it. You can relax , Nagios will alert you about your server bandwidth usage 🙂

  • MySql monitoring using nagios

    About :-

    Mysql Check is a very good plugin for nagios . We can use this to monitor mysql health status like mysql connection time , threads connected etc.

    Installation :-

    wget http://labs.consol.de/wp-content/uploads/2010/12/check_mysql_health-2.1.5.tar.gz

    tar -zxf check_mysql_health-2.1.5.tar.gz

    cd check_mysql_health-2.1.5


    make & make install


    In Mysql Server

    mysql> GRANT usage ON *.* TO ‘nagios’@’nagios-server-ip’ IDENTIFIED BY ‘pass’;

    Check the connection from nagios server

    $ ./check_mysql_health –hostname mysql-server  –username nagios –password pass  –mode connection-time

    Can’t locate Time/HiRes.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at ./check_mysql_health line 940.

    BEGIN failed–compilation aborted at ./check_mysql_health line 940.

    I got the above error while trying to check this plugin locally and I have fixed this using the following

    $  perl -MCPAN -e shell

    Can’t locate CPAN.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .).

    BEGIN failed–compilation aborted.

    ( cpan is not present in the server , so I have installed cpan first and installed all the other modules using cpan )

    $ yum install perl-CPAN

    $ perl -MCPAN -e shell

    $ cpan[1]> install Time::HiRes

    ./check_mysql_health –hostname mysql-server  –username nagios –password pass  –mode connection-time

    OK – 0.46 seconds to connect as nagios | connection_time=0.4560s;1;5

    ( This time its worked 🙂 )

    ./check_mysql_health –hostname mysql-server  –username nagios –password pass  –mode threads-connected

    CRITICAL – 34 client connection threads | threads_connected=34;10;20

    Nagios configuration

    # service ‘MySQL connection-time’

    define service{

    use                                   generic-service

    host_name                     MYSQL-Server

    service_description     MySQL connection-time

    check_command          check_mysql_health!nagios!pass!connection-time!2!4

    contact_groups            admins


    # service ‘MySQL threads-connected’

    define service{

    use                                 generic-service

    host_name                   MYSQL-Server

    service_description    MySQL threads-connected

    check_command   check_mysql_health!nagios!pass!threads-connected!80!100

    contact_groups          admins


    ( after editing the corresponding hosts cfg file verify the nagios configuration and restart the nagios serve r)

    $ nagios -v /etc/nagios/nagios.cfg

    $ /etc/init.d/nagios restart

    Hey you did that ..Its a fantastic nagios plugin  to monitor mysql health for high traffic DB server ‘s 😉