perl

Squelching SMS floods from Nagios being sent via a third party SMS provider

So at work they implemented some 'SMS Squelching' methods to interact with a 'mail > sms' gnokii script to try and 'squelch' megaloads of SMSs that come through from Nagios all at once. It's a bunch of perl and very much specific to working with a serial-attached Nokia and gnokii. The way it essentially worked was that if an SMS got queued to mail2smsgnokii/gsm's spool, the timestamp was compared with the last sms that got sent and if the length of time in between SMS was inside a threshold (say 30 minutes), the SMS would not be sent.

Nagios website regex pattern check

Here's a simple perl script that uses curl to search for a regex pattern on a website.

It returns status values that are Nagios compatible. This means you can write a command definition for Nagios that looks like this:

# regex check
define command{
        command_name    check_regex
        command_line    /usr/lib/nagios/plugins/check_regex $ARG1$ $ARG2$
}

And write a couple of service definitions like this:

define service {
        host_name                       foo
        service_description           foo regex

Perl script to send e-mail

#!/bin/perl

# Build an array of e-mail addresses to be Bcc'd to
my @bcc_addresses = (
'foo@bar.com',
'foo@bar2.com');

# The main recipient
my $to='foofoo@bar.com';

# Join the bcc addresses from the array, separate with comma
my $bcc = join(", ", @bcc_addresses);

# Where it's coming from
my $from='miguel@foobar.com';

# e-mail Subject
my $subject="Perl mail example";

# The e-mail content follows
my $out = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Nullam vestibulum dictum lectus.
Etiam at sapien. Donec fermentum dictum nisi. In ornare adipiscing massa.";

# Now let's fire up sendmail and push the data into it, then send
open(MAIL, "|/usr/sbin/sendmail -t");
print MAIL "To: $to\n";
print MAIL "Bcc: $bcc\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n";
print MAIL $out;

close(MAIL);

Pages

Subscribe to RSS - perl