monit-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Alert format question/feature request


From: Martin Pala
Subject: Re: Alert format question/feature request
Date: Wed, 7 Sep 2011 14:27:39 +0200

It is possible to use the "exec" action to run custom script when the event occurs. That script can then assemble the alert message including "top" output and send it using the "mail" command.

Example usage:

--8<--
   if cpu usage > 90% for 5 cycles then exec "/usr/loca/bin/send_top.sh address@hidden"
--8<--

where the /usr/loca/bin/send_top.sh script may look something like this:

--8<--
#!/bin/bash

OUTPUT="/tmp/top.out"

exec 1>$OUTPUT;
exec 2>&1

# monit event description
echo "Host: $MONIT_HOST" >
echo "Service: $MONIT_SERVICE"
echo "Event: $MONIT_EVENT"
echo "Description: $MONIT_DESCRIPTION"
echo "Date: $MONIT_DATE "
echo

# append the top output
/usr/bin/top -d1 -ocpu 10

#send the alert to users in the script arguments ($1, $2, …)
cat $OUTPUT | /usr/bin/mail -s "$MONIT_SERVICE: $MONIT_EVENT" $@
--8<--

(note: i didn't tested the script, may need some modifications)

Regards,
Martin


On Sep 6, 2011, at 11:33 PM, Daniel Rich wrote:

I just had a question from a fellow sysadmin that I don't think is possible in monit, but I figured I would ask the rest of the list:
Is it possible to get CPU and memory alerts to show us output from 'top', or something else to tell us the offending process(es)?
As a more general question, is there any way to embed the output of a command in an alert? I don't see a way to do it from the docs. For example, I might want to get the top 10 CPU users with a command like "top -d1 -ocpu 10" and have that be part of the alert e-mail.
-- 
Dan Rich <address@hidden> |   http://www.employees.org/~drich/
                               |  "Step up to red alert!"  "Are you sure, sir?
                               |   It means changing the bulb in the sign..."
                               |          - Red Dwarf (BBC)
--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general


reply via email to

[Prev in Thread] Current Thread [Next in Thread]