forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_aql_sms_credits.pl
executable file
·73 lines (55 loc) · 1.86 KB
/
check_aql_sms_credits.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2010-06-17 12:08:28 +0100 (Thu, 17 Jun 2010)
#
# http://github.com/harisekhon/nagios-plugins
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to check the remaining AQL SMS credits on an account for Nagios SMS Alerting";
# Credit to my ex-colleague Richard Harvey @ Specific Media for coming up with this idea
#
# This is a complete reimplementation of that idea using my personal library for improved code quality, error handling, perfdata
$VERSION = "0.5";
use strict;
use warnings;
use SMS::AQL;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
my $aql_user;
my $aql_password;
env_creds("AQL", "AQL account");
%options = (
%useroptions,
%thresholdoptions,
);
get_options();
$aql_user = validate_user($aql_user);
$aql_password = validate_password($aql_password);
validate_thresholds(1, 1, { "simple" => "lower", "integer" => 1 } );
set_timeout();
vlog2 "creating AQL instance";
my $sms = new SMS::AQL({
username => $aql_user,
password => $aql_password,
}) || quit "UNKNOWN", "Failed to connect to AQL: $!";
defined($sms) or quit "UNKNOWN", "failed to create AQL instance";
vlog2 "created AQL instance";
vlog2 "fetching credit number";
my $credit = $sms->credit();
unless($sms->last_status()){
quit "UNKNOWN", "Failed to retrieve credit from AQL: " . $sms->last_response();
}
defined($credit) or quit "UNKNOWN", "Failed to fetch AQL credit number";
isInt($credit) or quit "UNKNOWN", "invalid credit '$credit' returned by AQL, not a positive integer as expected";
$status = "OK";
$msg = "$credit SMS credits";
check_thresholds($credit);
$msg .= " | 'SMS Credits'=$credit;$thresholds{warning}{lower};$thresholds{critical}{lower};0;";
vlog2;
quit $status, $msg;