-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchk_megafonmsk_balance
More file actions
executable file
·75 lines (55 loc) · 2.15 KB
/
Copy pathchk_megafonmsk_balance
File metadata and controls
executable file
·75 lines (55 loc) · 2.15 KB
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
74
#!/usr/bin/perl
# icinga: -epn
use strict;
use Nagios::Plugin;
use LWP::UserAgent;
use Config::IniFiles;
my $np = Nagios::Plugin->new(
usage => "Usage: %s "
. "[ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ] -l|--login <login> -f|--conf <path-to-ini>",
);
$np->add_arg(
spec => 'critical|c=s',
help => '-c, --critical=INTEGER:INTEGER . See '
. 'http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT '
. 'for the threshold format. ',
);
$np->add_arg(
spec => 'warning|w=s',
help => '-w, --warning=INTEGER:INTEGER . See '
. 'http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT '
. 'for the threshold format. ',
);
$np->add_arg(
spec => 'login|l=s',
help => '-l, --login=LOGIN . '
. 'youmagic login '
. 'for the threshold format. ',
);
$np->add_arg(
spec => 'conf|f=s',
help => '-f, --conf=PATH Path to ini-file with passwords '
);
$np->getopts;
my $cfg = new Config::IniFiles( -file => $np->opts->conf ) || $np->nagios_exit( UNKNOWN, "Unable to read config at ".$np->opts->conf) ;
my $login = $np->opts->login;
my $password = $cfg->val( 'megafonmsk', "password_$login" );
my $agent = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
push @{ $agent->requests_redirectable }, 'POST';
$agent->cookie_jar({});
my $url = 'https://www.serviceguide.megafonmoscow.ru/ROBOTS/SC_TRAY_INFO';
my $response = $agent->post($url, [
'X_Username' => $login,
'X_Password' => $password
]);
$np->nagios_exit( UNKNOWN, "Unable to fetch response at $url, error: ".$response->status_line ) unless $response->is_success;
# забираем баланс телефона
$response->content =~ /<BALANCE>(.+?)<\/BALANCE>/;
$np->nagios_exit( UNKNOWN, "Unable to get balance from answer, content was ".$response->content ) unless (defined $1);
my $balance = $1;
$np -> add_perfdata( label =>"balance", value => $balance , threshold => 0 );
$np->nagios_exit(
return_code => $np->check_threshold($balance),
message => "Balance is $balance"
);
END { unlink("/tmp/.cookies.$$.txt"); }