Page 1 of 1

Email/SMS alert when state changed [howto]

Posted: Tue Nov 25, 2008 11:45 pm
by haus
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.