How to do checks on PRI lines

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

How to do checks on PRI lines

Post by donnyforbes »

How can I do checks on PRI lines. We are using FreePBX and Asterisk. Right now we have a perl script that runs on a monitoring server, but that is going away and that is why we want to add it to nagios checks. Here is what the script does now.

Code: Select all

[root@dozer ~]# more /usr/local/bin/check_pri.pl
#!/usr/bin/perl
use warnings;
use strict;

use Asterisk::AMI;
use Data::Dumper;
use XML::Dumper;

my @ALERT_EMAIL = ('[email protected]');
my @EMAIL = ('[email protected]');
my @SYSOP_PHONE = ('8300326', # justin work cell
                   '4535893', # carlos work cell
                   '7578034', # gene work cell
                );

#my @ALERT_EMAIL = ('[email protected]');
#my @EMAIL = ('[email protected]');
#my @SYSOP_PHONE = ('8300326');

my $PERSIST_FILE = '/var/check_pri_persist.xml';

my $telco_contact_info = "Telepacific Premium Support: 888-611-8722, Acct# 13460
7";
my $aggplant_info = "Agg Plant: (951) 736-7680, backup: (951) 736-7661";

my $CALLFILE_TEMP_DIR = '/var/tmp';
my $ASTERISK_OUTGOING_DIR = '/var/spool/asterisk/outgoing';

my $CALLALERT = 0;

# ALERT:
# 1 = ten minute alert to ALERT_EMAIL
# 2 = one minute alert to EMAIL
# 3 = 1 and 2

# VARIABLES YOU SHOULD EDIT.
my %dests = (
        'Hq Span 7' =>                  { ALERT => 3, SERVER => 'tank',      USE
R => 'pri_checker', SECRET => 'Wjm8A4C2n2379kq3', SPAN => 7, ALERTINTERVAL => 10
, ALERTTHRESHOLD => 5, CIRCUIT => '842641', PHONE => '', FAX => '' },
        'Hq Span 8' =>                  { ALERT => 3, SERVER => 'tank',      USE
R => 'pri_checker', SECRET => 'Wjm8A4C2n2379kq3', SPAN => 8, ALERTINTERVAL => 10
, ALERTTHRESHOLD => 5, CIRCUIT => '842635', PHONE => '', FAX => '' },
        'Yard Span 7' =>                { ALERT => 3, SERVER => 'ernestine', USE
R => 'pri_checker', SECRET => 'Wjm8A4C2n2379kq3', SPAN => 7, ALERTINTERVAL => 10
, ALERTTHRESHOLD => 5, CIRCUIT => '13/HCGS/848840//PT', PHONE => '', FAX => '' }
,
        'Yard Span 8' =>                { ALERT => 3, SERVER => 'ernestine', USE
R => 'pri_checker', SECRET => 'Wjm8A4C2n2379kq3', SPAN => 8, ALERTINTERVAL => 10
, ALERTTHRESHOLD => 5, CIRCUIT => '537994003.1 ????', PHONE => '', FAX => '' },
        );

my $persist = ();

if(-e $PERSIST_FILE)
{
        $persist = xml2pl($PERSIST_FILE);
}

foreach((keys %dests))
{
        my $dest = $_;

        my $astman = Asterisk::AMI->new(PeerAddr => $dests{$dest}{SERVER},
                                        Username => $dests{$dest}{USER},
                                        Secret   => $dests{$dest}{SECRET},
                                        Events   => 'off',
                        );

        my $response = $astman->action({ Action => 'Command',
                                         Command => 'pri show span ' . $dests{$dest}{SPAN},
                                        });

#       print Dumper(\$response);

        my $subject = '';
        my $body = '';

        my $var = undef;

        my @cmdnode = $response->{CMD};

        foreach my $cmds (@cmdnode)
        {
                foreach my $cmd (@{$cmds})
                {
#                       print "cmd: $cmd\n";

                        if($cmd =~ /Status: (.*)/) {
                                $var = $1;
                        }
                }
        }

#       print "dest: $dest, status: $var\n";

        unless(defined $var) {
                $var = 'Error: Unable to parse response';
                $subject = "Subject: Script Error - Pri Outage $dest\n\n";
                $body = localtime(time) .  " Unable to parse response.\nLooking for 'Status:' in: \n\n" . Dumper(@cmdnode);
        }
        else
        {
                if($var ne 'Up, Active')
                {
                        $subject = "Subject: Pri Outage $dest\n\n";
                        $body = localtime(time) . " $dest (SPAN: $dests{$dest}{SPAN}) = $var\n\n";
                }
        }

        if($subject ne '' && $dests{$dest}{ALERT} & 2)
        {
                open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq") or die "Can't fork for sendmail: $!\n";
                print SENDMAIL "From: Dozer Pri checker <prichecker\@allamericanasphalt.com>\n";
                foreach my $EMAIL (@EMAIL)
                {
                        print SENDMAIL "To: $EMAIL\n";
                }
                print SENDMAIL $subject;
                print SENDMAIL $body;
                print SENDMAIL $telco_contact_info;
                print SENDMAIL "\ntelco circuit ID: $dests{$dest}{CIRCUIT}";
                close(SENDMAIL) or warn "sendmail didn't close nicely";
        }


        push(@{$persist->{$dest}->{'StatusArray'}}, $var);

        my $arraylength = @{$persist->{$dest}->{'StatusArray'}};

        while($arraylength > $dests{$dest}{ALERTINTERVAL})
        {
                shift(@{$persist->{$dest}->{'StatusArray'}});
                $arraylength = @{$persist->{$dest}->{'StatusArray'}};
        }

        if($dests{$dest}{ALERT} & 1)
        {
                my $last_email = $persist->{$dest}->{LastEmail};

                if(!defined($last_email))
                {
                        $last_email = 0;
                }

                my $cutoff_time = $dests{$dest}{'ALERTINTERVAL'} * 60 + $last_email;

                if(time() >= $cutoff_time)
                {
                        # see if it's time to send an alert email...
                        my $non_up_count = 0;
                        foreach my $status (@{$persist->{$dest}->{'StatusArray'}})
                        {
                                if($status ne 'Up, Active' && $status ne 'testing')
                                {
                                        $non_up_count++;
                                }
                        }

                        if($non_up_count >= $dests{$dest}{ALERTTHRESHOLD})
                        {
                                # send email...
                                open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq") or die "Can't fork for sendmail: $!\n";
                                print SENDMAIL "From: Dozer Pri checker <prichecker\@allamericanasphalt.com>\n";
                                foreach my $EMAIL (@ALERT_EMAIL)
                                {
                                        print SENDMAIL "To: $EMAIL\n";
                                }
                                print SENDMAIL "Subject: Quantum Pri Outage $dest\n\n";
                                print SENDMAIL localtime(time) . "\n$dest span $dests{$dest}{SPAN} has been down >= $dests{$dest}{ALERTTHRESHOLD} times in t
he last $dests{$dest}{ALERTINTERVAL}\n\n" . Dumper(\$persist->{$dest});
                                print SENDMAIL $telco_contact_info;
                                print SENDMAIL "\ntelco circuit ID: $dests{$dest}{CIRCUIT}";
                                close(SENDMAIL) or warn "sendmail didn't close nicely";

                                $persist->{$dest}->{'LastEmail'} = time();


                                if($CALLALERT == 1)
                                {
                                        # create a call file...
                                        foreach my $sysop (@SYSOP_PHONE)
                                        {
                                                my $tmp_call_file = "$CALLFILE_TEMP_DIR/$dest-$sysop";
                                                $tmp_call_file =~ s/ /_/g;

                                                open(TMPFILE, ">", $tmp_call_file) or warn "couldn't open temp call file: $!";

                                                print TMPFILE "Channel: Local/$sysop\@mis-phone/n\n";
                                                print TMPFILE "MaxRetries: 50\n";
                                                print TMPFILE "RetryTime: 5\n";
                                                print TMPFILE "WaitTime: 5\n";
                                                print TMPFILE "Archive: yes\n";
                                                print TMPFILE "Extension: Dozer Pri monitor failure for $dest\n";
                                                print TMPFILE "Context: outbound-swift\n";

                                                close(TMPFILE);

                                                `mv $tmp_call_file $ASTERISK_OUTGOING_DIR`;
                                        }
                                }
                        }
                }
        }
}

# serialize this structure to disk...
pl2xml($persist, $PERSIST_FILE);

exit;
[root@dozer ~]#
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: How to do checks on PRI lines

Post by ssax »

There are a number of plugins on the exchange, you will need to test them out to make sure they meet your needs:

https://exchange.nagios.org/directory/P ... y/Asterisk

Maybe this one will work for you?

https://exchange.nagios.org/directory/P ... us/details
https://www.barryodonovan.com/2007/11/0 ... pri-nagios

Let us know if you have any questions.
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: How to do checks on PRI lines

Post by donnyforbes »

I used this one.
https://exchange.nagios.org/directory/P ... 1535394937

I went to this link. I have downloaded the plugin named check_asterisk_pri.php , next I went to Nagios XI and uploaded the plugin.
I am lost hear. What do I do next in order to get this working? Please provide me some information or assistance. I am really new to all of this.

thank you for your time.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: How to do checks on PRI lines

Post by ssax »

donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: How to do checks on PRI lines

Post by donnyforbes »

ssax wrote:Please follow this guide:

https://assets.nagios.com/downloads/nag ... ios-XI.pdf
I already downloaded and uploaded the plugin that I needed. This one above seems to be a generic one.
I am not trying to do "countdown_to_date....

The question I have is after I downloaded and upload the plugin where do I got next to get this working.
I have found this link https://www.barryodonovan.com/2007/11/0 ... pri-nagios

Except the version I am using is newer then this and I don't see these files anywhere.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: How to do checks on PRI lines

Post by scottwilkerson »

Locking thread as a tick has been opened
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked