Monitoring Script

Hello All,

I have written a script which will grep for error codes in a file and if the count for the same is about 500 it will send and smpp alert.

Here is my code.

#!/bin/bash

#########################################################################################################
# Shellscript   :       codecheck_trans.sh -Status Code Check 
# Version       :       V1.0
# Owner         :       Siddhesh Khavnekar <siddhesh.khavnekar@mobixell.com>
# Date          :       2012-01-14
# Category      :       Files Management
#########################################################################################################
# Description   :       This scipt will Monitor traffic on XMP service blades 6-16 and for HTTP error 500
#
#########################################################################################################

#Defining Variable
#------------------------
LOGSCAN=/opt/xmp/bin/logscan
HOST=`hostname`
LOG_FILE=/var/xmp/log/XMP_*
HTA_TRNS_STATUS=`logscan -in $LOG_FILE -select 'LSA_LogicalLog.indexOf("TCP-ROUTER")==0 && this["HTA_ResponseStatus"]=="500"'|grep  HTA_ResponseStatus| wc -l`


if [ $HTA_TRNS_STATUS -gt 500 ]; then
 echo " Too many HTTP 500 Errors observed in activity log of $HOST !!! "


echo "Trap has been sent because $HTA_HTTP_STATUS 500 status code has been observed for Transperent Traffic"
snmptrap -v 2c -c mobilewebproxy 10.201.1.99:162 '' 1.3.6.1.4.1.12702.9.10000.6 1.3.6.1.4.1.12702.9.10000  s "$HTA_HTTP_STATUS - 500 error code observed on $HOST for Transperent traffic..Please Check Immediatelly..!!"

fi

exit 0

It works well. I need to modify the same as per the new requirements of my client.

The above code only greps for error code 500. i also want to grep the error code 200 and the same should be sent through mail.

Any help is appreciated.

Thanks,
Siddh

Just an guess (never used logscan):

Or can you please post a sample of the /var/xmp/log/XMP_* ?
Maybe you can have a cleaner and simpler script, using only grep.

Hello,

Thanks for the reply. Here is the out of logscan command

LSA_Component: DSP
LSA_Event: DSP_REQUEST_COMPLETED
LSA_EventTime: 1323670604.232056
LSA_LogicalLog: TCP-ROUTER.tswebpxmp6.9_LOG
LSA_SequenceNumber: 201112061008190991914820030473202
NAI3_OP: NAI3_OP_AUTHORIZE
HTA_RespHdr_x-content-type-options: nosniff
HTA_RespHdr_x-xss-protection: 1; mode=block
HTA_ResponseReason: OK
HTA_ResponseStatus: 200
HTA_SearchString:

The command mentioned will give the count of 200 error code. that works fine.

I need to know how do i take this output and mail to the concened mail id?

-SK

One way:

if [ $HTA_TRNS_STATUS -gt 500 ]; then
 echo " Too many HTTP 500 Errors observed in activity log of $HOST !!! " | mail -s "HTTP 500 Errors" user@example.com