Email/SMS alert when state changed [howto]

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
haus
Posts: 195
Joined: Thu Oct 11, 2007 5:10 am

Email/SMS alert when state changed [howto]

Post by haus » Tue Nov 25, 2008 11:45 pm

If you want to get an email/SMS alert when the runstate of your ZM box changes, go to line 110 of /usr/bin/zmpkg.pl.

After "Info( "Updating DB: $state->{Name}\n" );", and add these lines:

Code: Select all

my $newstate = uc $state->{Name};
open(SENDMAIL, "|/usr/sbin/sendmail -oi -t -f<FROM_ADDRESS> -odb") or die "Can't fork for sendmail: $!\n";
print SENDMAIL <<"EOF";
To: <EMAIL_ADDRESS>
Subject: ZoneMinder: $newstate

EOF
close(SENDMAIL);
With these important caveats:

1. there is no space between "-f" and the from address. If your from address is "installer@myzone.com", it should read "-finstaller@myzone.com"

2. <EMAIL_ADDRESS> has to be escaped. If your to: address is recipient@myzone.com, it should look like "To: recipient\@myzone.com".

Hope that helps...kind of a nice touch. Now I can pull my USB stick on the way out and get a confirmation that the system actually armed. Not that it has ever failed so far, but still nice to know.

This only works when the runstate changes, not when the system is started or stopped (those are other code blocks within zmpkg.pl). You can modify the code and placement if that information is important to you, etc.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests