monitor script (82 Views)
Reply
Super Advisor
Ragni Singh
Posts: 468
Registered: ‎04-23-2001
Message 1 of 8 (82 Views)

monitor script

Hi All,

I am trying to write a monitor script that sends a opcmon message to openview. How can I do that. Any help is greatly appreciated. This is what I would like to do.

ps -ef | egrep '(processManager|fbam|fbdm|pcxsml|fb.*io|pcxrm|fbmoc|fbdbx)' | cut -c49-84 |grep -v egrep
if [ $? -eq 0 ]
then

# FBHH processes are still running.
echo "\nFBHH processes are still running.\n"
exit 1

else

echo "\nFBHH successfully shutdown.\n"

fi
Once again, any help will be greatly appreciated. I want to put this in a script and be able to send a opcmon message to openview.
Please use plain text.
Honored Contributor
Ken Hubnik_2
Posts: 563
Registered: ‎05-20-2002
Message 2 of 8 (82 Views)

Re: monitor script

You can use the logger command and funnel the output to syslog.
Please use plain text.
Super Advisor
Ragni Singh
Posts: 468
Registered: ‎04-23-2001
Message 3 of 8 (82 Views)

Re: monitor script

what is this logger command you are talking about?
Please use plain text.
Honored Contributor
Jean-Louis Phelix
Posts: 724
Registered: ‎10-07-2002
Message 4 of 8 (82 Views)

Re: monitor script

hi

You just have to change your echo command by a 'opcmon' command.

opcmon [ -help ] = [ -object ] [ -option variable>= ]*

Regards
It works for me (© Bill McNAMARA ...)
Please use plain text.
Honored Contributor
Ken Hubnik_2
Posts: 563
Registered: ‎05-20-2002
Message 5 of 8 (82 Views)

Re: monitor script

logger is an interface to get messages or output into /var/adm/syslog/syslog.log.
Look at the man pages on logger.
Please use plain text.
Honored Contributor
Robin Wakefield
Posts: 861
Registered: ‎06-14-1998
Message 6 of 8 (82 Views)

Re: monitor script

Sanjay,

See if this gives you what you want:

#!/usr/bin/ksh

opcmsg="/opt/OV/bin/OpC/opcmsg"

function opcm
{
severity="${1}"
text="${2}"
${opcmsg} severity=$severity application=misc object=misc msg_text="${text}"
}

ps -ef | egrep '(processManager|fbam|fbdm|pcxsml|fb.*io|pcxrm|fbmoc|fbdbx)' | cut -c49-84 |grep -vq egrep

if [ $? -eq 0 ]
then

# FBHH processes are still running.
opcm warning "FBHH processes are still running."
exit 1

else

opcm normal "FBHH successfully shutdown."

fi

Rgds, Robin
Please use plain text.
Valued Contributor
David Totsch
Posts: 44
Registered: ‎02-07-1999
Message 7 of 8 (82 Views)

Re: monitor script

I know, you only asked about how to forward a message, but I couldn't resist (maybe it is because I am full of turkey)...

Shell scripts are not very efficient, so take a moment to make sure your script is as slim as possible:

1) when passing output from ps(1) to grep(1), grep will have less work to do if you pass less information. You can limit ps to a particular user with the "-u" option and the user name as an argument. So, instead of 'ps -ef | grep oracle', you could 'ps -fu oracle'.

2) grep already does a lot of work looking for regular expressions, but adding the alternations ("|") increases the work exponentially. Consider putting the list of process names into a file, and using fixed string grep to find them ('ps -Ff ')

3) run as few commands as possible. First, 'grep -v grep' can always be avoided by clever regular expression formulation. For example, 'ps -ef | grep something' will match itself in the process stack, but 'ps -ef | grep [s]omething' will not match itself (but you could always only pass 'ps -e' information when looking for a process name and not a user name or argument). Also, avoid using several commands where one or two will do (awk can look for regular expressions like grep and pass output like cut -- and passing grep output to awk is kinda silly, unless you have a major code readability problem). [Yes, I know awk is a bigger command to load.]

4) make commands do more of the work. I kinda just got through saying that, but instead of 'ps -fu oracle | grep [l]istener | wc -l' consider 'ps -fu oracle | grep -c [l]istener'. You can also avoid the overhead of redirecting stdout & stderr by using the "-q' option to grep when you are just checking the exit status (saves some room on the command-line, too).

5) when looking for processes, I like to construct an array of PIDs so that I can use the following simplified code to check for them in the process stack:

for PID in ${PIDArray[@]}
do
if ps -fp $PID > /dev/null 2>&1
then
: # it is in the stack
else
: # process is missing!
fi
done

Enjoy,
-dlt-
Please use plain text.
Occasional Visitor
Liselotte Pettersson
Posts: 5
Registered: ‎02-17-1998
Message 8 of 8 (82 Views)

Re: monitor script

First you have to create to monitors in VPO that are listening.
Ex:PROCESS_DOWN
PROCESS_UP
You set up the PROCESS_DOWN-monitor as "Program" that is running your script.
The "PROCESS_UP-monitor" is "external" and just listening.This one can close the "DOWN_alarm" in message-correlation.

Put in "OPCMON=/opt/OV/bin/OpC/opcmon"
MON1=PROCESS_DOWN
MON2=PROCESS_UP

in your script.

ps -ef | egrep '(processManager|fbam|fbdm|pcxsml|fb.*io|pcxrm|fbmoc|fbdbx)' | cut -c49-84 |grep -v egrep
if [ $? -eq 0 ]
then

# FBHH processes are still running.
#echo "\nFBHH processes are still running.\n"
$OPCMON "$MON1=3
$OOPCMON "MON2=3

else

#echo "\nFBHH successfully shutdown.\n"
$OPCMON "$MON1=0
$OPCMMON "MON2=0

fi

I should change the script, so the successfully larm just come when the process up again, not every time the script is running.

Good luck!

/Lisa
Lisa
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation