Monitoring Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Monitoring Script
# 1  
Old 01-15-2012
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.

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
# 2  
Old 01-15-2012
Just an guess (never used logscan):
Quote:
Originally Posted by Siddheshk
Code:
HTA_TRNS_STATUS=`logscan -in $LOG_FILE -select 'LSA_LogicalLog.indexOf("TCP-ROUTER")==0 && this["HTA_ResponseStatus"]=="200"'|grep  HTA_ResponseStatus| wc -l`

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.
# 3  
Old 01-15-2012
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
# 4  
Old 01-15-2012
One way:
Code:
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with a monitoring script

I currently have a shellscript to check the size of a filesystem and email me if the size is over a certain percentage (80%). I have this script on crontab and executes the shell every 10 mins. I have the above in place on 8 servers. It so happens that a file system on one of the servers is... (1 Reply)
Discussion started by: goddevil
1 Replies

2. UNIX for Advanced & Expert Users

ldapsearch in monitoring script without bind password written in script

Hi I do a very simple monitoring of our OpenLDAP (runs in cronjob and generate alerts if unsuccessfull) $ ldapsearch -h hostname.domain -D "cn=monitor_user,ou=People,dc=organisation" -w "password" -b "dc=organisation" -x "(&(cn=monitor_user)(ou=People))" dn | grep -v version dn:... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

3. Red Hat

monitoring script

Hi, I ned to monitor the memory for the red-hat machine,when its reaches a threshold value like 2GB then a mail should be sent as soon as it finds the the value is met can you suggest me which is the best way to do this? (2 Replies)
Discussion started by: sriniv666
2 Replies

4. Shell Programming and Scripting

Monitoring script

Hi, I want to write script that monitors particular ports in a server. I completed the script but.... If the server is restarted i need manually start the script.. Is there any way i can make the script start by it self after the server reboot........ Thanks, Firestar (4 Replies)
Discussion started by: firestar
4 Replies

5. Shell Programming and Scripting

Help with Monitoring script

Hi Gurus, Currently I am learning UNIX through online forums and unix blogs. I have the below requirement. I need to write a script to monitor server processes. For example, there are 3 processes currently running on the server.(java, pmrepagent, pmserver). If any of the process goes down,... (2 Replies)
Discussion started by: svajhala
2 Replies

6. Shell Programming and Scripting

Archivelog monitoring Script

Could anyone please help? I have written a small program that's actually working fine for me and extracting all the details I required. What code does is, it goes to all archivelog directories and see if archivelog backup was failed or successful <<CODE>> ... (2 Replies)
Discussion started by: anjum.suri
2 Replies

7. Shell Programming and Scripting

IP Monitoring Script

Dear All, I am new to Shell Programming, but I need a script which will monitor the different IP's in the live logs. Condition:- The script will monitor the logs continously and should print only those IP's which exists more than 3 times per day. Please do help me. Thanks and... (1 Reply)
Discussion started by: akhtar.bhat
1 Replies

8. Solaris

Monitoring Script

Hi, I want to write a script that will monitor cpu,mem usage and disk usage for entire day and data will be redirected to file, (4 Replies)
Discussion started by: manoj.solaris
4 Replies

9. UNIX for Advanced & Expert Users

monitoring script

i have a unix batch written in c, dealing with really time-consuming database operations i want to write a ksh script to monitor its performance. which items i should monitor? do you have any suggestions? 1)cputime 2)swap area 3)pmem 4) 5) what else? (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies

10. UNIX for Dummies Questions & Answers

monitoring script

hi can someone help me to write a script to monitor the growth of the directory running at 5 hours interval and then pipe it to a file :(? i only know the manual command "du -sk" and the worst i dun know anything about script. (3 Replies)
Discussion started by: legato
3 Replies
Login or Register to Ask a Question