[Gllug] PERL/Nagios Experts
jan at henkins.za.net
Fri Sep 10 10:27:43 UTC 2010
On 10/09/10 11:00, Sunny Aujla wrote:
> Hi All,
> Just want some advice. I need to know if it is possible to do the
> Here is the scenario:
> I have a Nagios system which monitors the devices we develop. When
> the host is down, it sends a email to our Helpdesk email. We have a
> NAS (Network Sound Server) which plays a sound when there is a host
> down. Currently it just plays one sound file for all devices.
Sorry to sound confused, but NAS != Network Sound Server, AFAIK it means
"Network Attached Storage"...
> I would like to have something like a perl wrapper which will look at
> the email, extract which device is down and play the particular sound
> file according to the device. for example: "Device A is down" or
> "Device B is down".
> Can this be easily done?
From what I can visualise from the limited info above, yes you can do
it using a script of some sort. Perl will work, BASH with formail will
also work. You can test this quite easily on a Linux box by adding the
script to a .forward file in the home directory of the user you are
sending mail to. It should look something like this:
Important to note the quotes around the first line, which denotes a pipe
to an external program, in this case your perl script. The "anotheruser"
is an optional entry. Why I include that here, is that it is important
to note that the mail message will be discarded after it is sent through
the pipe to the perl script. If you want to keep a copy of the mail, you
have to put in a mailbox name in place of "anotheruser", either the same
one you are using for this exercise, or another local user. It could be
a full email address of a mailbox on another system, for that matter.
To get back to the script, what basically happens with the pipe is that
you are pushing the full contents of the email message trough your
script. The nice thing with this is that you can easily do regex and
pattern matching based on headers or strings in the message body,
whatever you want to do. Fairly straightforward as these things goes.
PS: I run a system using this principle as an email to SMS gateway for
the company I work for.
Gllug mailing list - Gllug at gllug.org.uk
More information about the GLLUG