Monday, May 6, 2013

shell script for Generate the service.cfg for monitoring network device interfaces


#!/bin/bash
#Purpose : TO generate interface monitoring services.cfg



while read devicelist

do
ip=`echo $devicelist | awk '{print $2}'`
devicename=`echo $devicelist | awk '{print $1}'`

`snmpwalk -Os -c communitystring -v 1 $ip IfDescr | awk '{print $4}' > /tmp/interface.txt`


while read interfacename

do


echo "define service{
        host_name                       $devicename
        service_description             $interfacename
        use                             service
        check_command                   check_ifoperstatus!$interfacename!communitystring
}"

done < /tmp/interface.txt

done < /tmp/deviceip

Thursday, April 18, 2013

AIX5.3/6.1 NRPE install- pre-compiled



Monitoring AIX with Nagios

Purpose

This document describes how to monitor AIX servers using Nagios.

Overview

These instructions cover how to install and use pre-compiled binaries to monitor AIX 5.3 using NRPE.

Download Pre-Compiled Binaries

You will need to download two packages of pre-compiled binaries to your AIX server.
First download the pre-compiled Nagios plugin binaries for AIX 5.3 from the following URL:
cd /tmp
aix53_nrpe-nsca-plugins.tgz
Next download the pre-compiled NRPE binaries from the above URL as well:
AIX-5.3-nrpe-2.12-binaries.tar.gz

Create Directories

Login to your AIX server as the root user and run the following commands:
cd /usr/local
mkdir nagios
cd /var
mkdir run
cd run
touch nrpe.pid
And now change owner to nagios as
chown –R nagios.nagios ../run

Unpack Binaries

Next unpack the pre-compiled plugins and place the extracted files into the /usr/local/nagios directory using commands similar to the following:
cd /tmp
gunzip < aix53_nrpe-nsca-plugins.tgz | tar xvf –
cd /tmp/nagios
cp -R * /usr/local/nagios
Next, unpack the prec-ompiled NRPE binaries using commands similar to the following:
cd /tmp
gunzip < AIX-5.3-nrpe-2.12-binaries.tar.gz | tar xvf -
cp usr/local/nagios/bin/nrpe /usr/local/nagios/bin
cp usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/etc

Create Nagios User and Group

Next, create a Nagios user and group on the AIX server.
Use the following command to create a new group:
mkgroup nagios
Make a home directory for a Nagios user using the following command:
cd /users/
mkdir nagios
Next, open up smitty and add a group and new user with the name
users and nagios. Launch smitty with the following command:
smitty group
                Group Name = users                                                 


smitty user
Once smitty openes, select Add a user, and use the
following settings:
• User NAME = nagios
• Primary Group = users
• Group SET = users,nagios
• HOME directory = /users/nagios

Set Permissions

Change folder permissions so NRPE will operate properly, with the following command:
chown -R nagios.nagios /usr/local/nagios
Verify the permissions on the directory using the following commands:
cd /usr/local/nagios
ls –l to check the permission

Specify NRPE Port Number

Next, edit the /etc/services file to add a port number for NRPE.
To edit the file, use the following command:
vi /etc/services
Add a line to the file that looks exactly like this:
nrpe 5666/tcp #nrpe
Save the file.

Edit the nrpe.conf

Comment the following line as shown below:
comment #server_address=127.0.0.1
 #allowed_hosts=127.0.0.1 in nrpe.conf

Configure NRPE for Automatic Startup

Next, configure NRPE to automatically start when the AIX server reboots. To do this, use the following command:
nohup /usr/local/nagios/bin/nrpe -n -c /usr/local/nagios/etc/nrpe.cfg –d
You should get this reponse:
Sending nohup output to nohup.out.
Note: The -n flag specifies that the NRPE server should run without SSL support. This reduces security of the NRPE daemon, but dramatically increases performance under heavy server load and may be okay if your server is on an internal network protected by a firewall.

Start NRPE

Start NRPE using the following command:
/usr/local/nagios/bin/nrpe -n -c /usr/local/nagios/etc/nrpe.cfg –d

Test Your NRPE Configuration

Test your AIX server to see if NRPE is running properly. To do this, use the following command:
ps -ef | grep nrpe
You should see something that looks like this:
nagios 111345 43675 /usr/local/nagios/bin/nrpe –c /usr/local/nagios/etc/nrpe.cfg -n –d
Note: The output you see may differ slightly, as the PID number will be different on your system.
Important: If you don't see any output when running the above command, it means something is wrong with your setup! This may be related to problems in your NRPE configuration file (/usr/local/nagios/etc/nrpe.cfg).

Monday, April 1, 2013

Nagios service dependency configuration generator script


#!/bin/bash
#Date : 1st April 2012
#Purpose : Nagios service dependency configuration generator script
#Authors : Babu Dhinakaran S and Ranjith Kumar R


`grep host_name /usr/local/nagios/var/status.dat | cut -d= -f2 | sort | uniq > /tmp/servers`

while read line
do
`grep -A1 -B0 $line /usr/local/nagios/var/status.dat | grep service_description | cut -d= -f2 | sort | uniq > /tmp/tempvariable`
count=`wc -l < /tmp/tempvariable`
if [ $count -le 1 ]
then
check=`cat /tmp/tempvariable`
if [ "$check" == "PingCheck" ] || [ "$check" == ""  ]
then
echo $line
fi

else
temp=""
        while read line2
                do
                if [ "$line2" != "PingCheck" ]
                then
                temp=`echo $temp,$line2`
                fi
        done < /tmp/tempvariable

# remove the comma
temp=$(echo $temp | cut -c 2-)


`echo "define servicedependency{
        host_name                       $line
        service_description             PingCheck
        dependent_host_name             $line
        dependent_service_description   $temp
        execution_failure_criteria      n
        notification_failure_criteria   u,c
       }" >> /tmp/ibsserdepdefinition.txt`

fi
done < /tmp/servers

Friday, October 12, 2012

Script to check Certificates validity in the Java Key Store


To check Certificates in the Java Key Store:

#!/bin/bash
# Nagios plugin to check the expiration dates
# of Java Cert keystores

# Set up some variables
# Todays date expressed in Epoch time "seconds since 1970-01-01 00:00:00 UTC"
TODAY=`date +"%s"`
critical=$2
warning=$1
c_flag=0
w_flag=0
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
count1=0
count2=0
diffdays_c="in"
diffdays_w="in"

# keytool location and command line
# keytool normally lives here - /opt/java/x64/jdk1.6.0_18/bin/keytool
KEYTOOL="/opt/java/x64/jdk1.6.0_18/bin/keytool"

# Keystore varies depending on application. The below example is from prod
# It can normally be found here /opt/apps/<APPLICATION>/conf/TrustStore_PROD.ks
KEYSTORE="/opt/apps/cmc-clientverification02/conf/TrustStore_PROD.ks"

# Keystore password
KEYPASS="changeit"

# So first we go and get the cert experation dates from the keystore using the
# keytool
`$KEYTOOL -list -v -storepass $KEYPASS -keystore $KEYSTORE | grep Valid |  awk '{print $10,$11,$12,$13,$15}' > /tmp/cert.txt`

if [ -s /tmp/cert.txt ];then

lastrun=`echo $?`
if [ $lastrun  -eq 0  ]; then

while read line
do
 certepoch=`date --date="$line" "+%s"`
 diff=$(($certepoch - $TODAY))
  diff_days=$(($diff / 86400))
  if [ $diff_days -le $critical ];then
        #echo "CRITICAL:Certificate will expire in $diff_days days"
        c_flag=2
        count2=$((count2 + 1))
        diffdays_c="$diffdays_c $diff_days"
        #exit $CRITICAL
  fi
if [ $diff_days -ge $critical ] && [ $diff_days -le $warning ];then
        #echo "WARNING:Certificate will expire in $diff_days"
        w_flag=1
        count1=$((count1 + 1))
        diffdays_w="$diffdays_w $diff_days"
        #exit $WARNING
  fi

done < /tmp/cert.txt
else
        echo "UNKNOWN: check the command executing manually"
        exit $UNKNOWN

fi

if [ $c_flag -eq $CRITICAL ] && [ $w_flag -eq $WARNING ];then
        echo "CRITICAL:There are $count2 certificates getting expired $diffdays_c days"
        echo "and certificate in WARNING:There are $count1 certificates getting expired $diffdays_w days"
exit $CRITICAL
fi


if [ $c_flag -eq $CRITICAL ];then
        echo "CRITICAL:There are $count2 certificates getting expired $diffdays_c days"
        exit $CRITICAL
fi

if [ $w_flag -eq $WARNING ];then
        echo "WARNING:There are $count1 certificates getting expired $diffdays_w days"
        exit $WARNING
fi

if [ $c_flag -eq $OK ] && [ $w_flag -eq $OK ];then

        echo "OK:There are no certificates getting expired."
        exit $OK

fi

else

echo "Try running the Keytool command manually, ther might be a chance that there are no certificates"
exit $CRITICAL
fi

VBScript to find Fileage and send an e-mail

This summary is not available. Please click here to view the post.

Check_Churn script;This script will basically to see how much the log files are changing over a user defined period of time

Check_Churn script;This script will basically to see how much the log files are changing over a user defined period of time.
It's useful to check how if there are any delay in getting a logfile updated from the start of the file o the end of the file at some instance(depends on the schedule time of the script as well).

Syntax to follow: C:\>cscript /nologo "c:\Documents and Settings\bdhinakaran\Desktop\VbScript\chec
k_churn.vbs" -d "c:\\" -p "(iiCFDFXLIVE-SyslogHub-3.3.3-instance1\[(\d)\]).log"
-c 90



''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'On Error Resume Next

adir = Wscript.Arguments.Item(0)
dir = Cstr(Wscript.Arguments.Item(1))
aPatternMatch = Wscript.Arguments.Item(2)
PatternMatch = Cstr(Wscript.Arguments.Item(3))
acri = Wscript.Arguments.Item(4)
cri = CLng(Wscript.Arguments.Item(5))


If adir = "-d" and aPatternMatch = "-p" and acri = "-c" Then
 
 
   Const adVarChar = 200
   Const MaxCharacters = 255
   today = now()
   Set DataList = CreateObject("ADOR.Recordset")
   DataList.Fields.Append "FileName", adVarChar, MaxCharacters
   DataList.Fields.Append "FileDateCreated", adVarChar, MaxCharacters
   DataList.Open
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set hash = CreateObject ("Scripting.Dictionary")
   If fso.FolderExists(dir) Then
    Set f = fso.GetFolder(dir)
    Set fc = f.Files
     
    For Each file in fc
      's = s & file.name & " " & "DateCreated "& file.DateCreated
 'hash.add file.name, file.DateCreated
      's = s &   VbNewLine
 'count = count + 1

 Set myRegExp = New RegExp
      myRegExp.IgnoreCase = True
      myRegExp.Global = True
      myRegExp.Pattern = patternMatch
      'Wscript.Echo "Pattern Match:" & patternMatch
      Set myMatches = myRegExp.Execute(file.Name)
      If myMatches.count > 0 Then
    DataList.AddNew
    DataList("FileName") = Cstr(file.name)
    DataList("FileDateCreated") = file.DateCreated
    DataList.Update
count = count + 1
'Wscript.Echo "Matched Pattern:" & patternMatch
 End If

    Next
      'Wscript.Echo "No Pattern Match Found in the specified Directory:" &dir
  'Wscript.Echo "Total Files:"&count
   Else
Wscript.Echo "Folder doesn't exists. Please check the path"
Wscript.Quit(2)
   End If

If count > 1 Then
DataList.Sort = "FileName asc" 'sort the disconnected recordset to asc by default it sorts to ascending if needed can sort to desc
DataList.MoveFirst
diff1 = DateDiff("s",DataList.Fields.Item("FileDateCreated"),today)
DataList.MoveLast
diff2 = DateDiff("s",DataList.Fields.Item("FileDateCreated"),today)
rdiff = diff1 - diff2
'Wscript.Echo "Real diff in Second for the FirstFile and LastFile:" & rdiff &"sec"

'Displays the overall fields
'DataList.MoveFirst
'Do Until DataList.EOF
' Wscript.Echo DataList.Fields.Item("FileName") & vbTab & DataList.Fields.Item("FileDateCreated")
' DataList.MoveNext
'Loop

If cri > rdiff Then
Wscript.Echo "Creation Time of the First Log file and Last LogFile is less than the user-defined time:" & rdiff &"sec" &"in the directory: " &dir
Wscript.quit(0)

Else
Wscript.Echo "Is more than the user-defined time: " & rdiff &" sec " & " in the directory: " &dir
Wscript.Quit(2)
End If

'keys = hash.Keys
'items = hash.Items
'for i = 0 to hash.Count - 1
'wscript.echo Keys(i) & " = " & hash.item(Keys(i))
'next

'diff1 = DateDiff("s",hash.item(Keys(0)),today)
'diff2 = DateDiff("s",hash.item(Keys(hash.Count - 1)),today)

'Wscript.Echo "The First File Difference with the today's date:" & diff1
'Wscript.Echo "The Last File Difference with the today's date:" & diff2
'rdiff = diff1 - diff2
'Wscript.Echo s
'Wscript.Echo "Real diff in Second for the FirstFile and LastFile:" & rdiff &"sec"
'Wscript.Echo "Total Files:" & hash.Count
     Else
'DataList.MoveFirst
'Do Until DataList.EOF
'Wscript.Echo DataList.Fields.Item("FileName") & vbTab & DataList.Fields.Item("FileDateCreated")
'DataList.MoveNext
'Loop
Wscript.Echo "We have single record or file in the specified Directory or no files of the patten match specified: " & dir
Wscript.Quit(2)
End If
  Else
   Wscript.Echo "Please follow the pattern: check_churn.vbs -d <directory> -p <pattern> -c <error_sec> "
   Wscript.echo "This script will basically to see how much the log files are changing over a user defined period of time"
   Wscript.Quit(2)
End If

Wednesday, September 26, 2012


HOWTO – Add check_db Plug-in (check_db)

The plug-in can be found at nagios exchange bu this is a modified version which actually uses SERVICE_NAME instead of SID. This has been loaded with the new JDBC connectivity driver for the new Oracle server Connectivity.

Description:

Nagios plugin to check output of a Oracle sql query, matched with a regular expression. This checks the numeric data to the matched regular expression.
Remote oracle database check using JDBC drivers. Supports custom SQL queries and regular expression match. Provides similar functionality as SiteScope DB monitor. This plug-in can check almost every aspect of oracle database

The plug-in uses JSAP command line parser from http://www.martiansoftware.com/jsap/  and a ojdbc6.jar class file for the connectivity.

This plug-in involves basically 4 component check_db , DbCheck.class/DbCheck.java , ojdbc6.jar and JSAP-2.0a.jar

You can get the completed doc and file at this location: https://skydrive.live.com/redir?resid=7109A4AA026A5AFB!112