line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix::Check::Redis; |
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Zabbix::Check::Redis - Zabbix check for Redis service |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
version 1.11 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Zabbix check for Redis service |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
1
|
|
|
1
|
|
1494
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
45
|
|
16
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
17
|
1
|
|
|
1
|
|
16
|
use v5.10.1; |
|
1
|
|
|
|
|
3
|
|
18
|
1
|
|
|
1
|
|
4
|
use Lazy::Utils; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
131
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
7
|
use Zabbix::Check; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
103
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
BEGIN |
24
|
|
|
|
|
|
|
{ |
25
|
1
|
|
|
1
|
|
5
|
require Exporter; |
26
|
1
|
|
|
|
|
3
|
our $VERSION = '1.11'; |
27
|
1
|
|
|
|
|
10
|
our @ISA = qw(Exporter); |
28
|
1
|
|
|
|
|
3
|
our @EXPORT = qw(_installed _discovery _running _info); |
29
|
1
|
|
|
|
|
728
|
our @EXPORT_OK = qw(); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our ($redis_server) = whereis('redis-server'); |
34
|
|
|
|
|
|
|
our ($redis_cli) = whereis('redis-cli'); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub bind_to_redis_cli_args |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
0
|
0
|
|
my ($bind) = @_; |
40
|
0
|
0
|
|
|
|
|
return "" unless defined($bind); |
41
|
0
|
0
|
|
|
|
|
if ($bind =~ /^([^:]*):(\d*)$/) |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
|
|
|
my ($host, $port); |
44
|
0
|
|
|
|
|
|
$host = "127.0.0.1"; |
45
|
0
|
0
|
|
|
|
|
$host = shellmeta($1, 1) if $1 ne ""; |
46
|
0
|
|
|
|
|
|
$port = "6379"; |
47
|
0
|
0
|
|
|
|
|
$port = shellmeta($2, 1) if $2 ne ""; |
48
|
0
|
|
|
|
|
|
return "-h $host -p $port"; |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
|
$bind = shellmeta($bind, 1); |
51
|
0
|
|
|
|
|
|
return "-s $bind"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get_info |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
0
|
|
0
|
0
|
|
return unless $redis_cli; |
57
|
0
|
|
|
|
|
|
my ($bind) = @_; |
58
|
0
|
|
|
|
|
|
my $redis_cli_args = bind_to_redis_cli_args($bind); |
59
|
|
|
|
|
|
|
my $result = file_cache("all", 30, sub |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
0
|
|
|
my $result = { 'epoch' => time() }; |
62
|
0
|
|
|
|
|
|
my $topic; |
63
|
0
|
|
|
|
|
|
for (`$redis_cli $redis_cli_args info 2>/dev/null`) |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
|
|
|
chomp; |
66
|
0
|
0
|
|
|
|
|
if (/^#(.*)/) |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
|
|
|
$topic = trim($1); |
69
|
0
|
|
|
|
|
|
next; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
my ($key, $val) = split(":", $_, 2); |
72
|
0
|
0
|
0
|
|
|
|
next unless defined($topic) and defined($key) and defined($val); |
|
|
|
0
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$key = "$topic:".trim($key); |
74
|
0
|
|
|
|
|
|
$val = trim($val); |
75
|
0
|
|
|
|
|
|
$result->{$key} = $val; |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
return $result; |
78
|
0
|
|
|
|
|
|
}); |
79
|
0
|
|
|
|
|
|
return $result; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _installed |
83
|
|
|
|
|
|
|
{ |
84
|
0
|
0
|
|
0
|
|
|
my $result = $redis_server? 1: 0; |
85
|
0
|
|
|
|
|
|
print $result; |
86
|
0
|
|
|
|
|
|
return $result; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _discovery |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
0
|
|
|
my @items; |
92
|
0
|
|
|
|
|
|
for (`ps -C redis-server -o pid,cmd 2>/dev/null`) |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
|
|
|
|
|
chomp; |
95
|
0
|
0
|
|
|
|
|
if (/^(\d*)\s+\Q$redis_server\E\ (\S+)/) |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
|
|
|
push @items, { bind => $2 }; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
return print_discovery(@items); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _running |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
0
|
|
|
my ($bind) = @_; |
106
|
0
|
|
|
|
|
|
my $result = 2; |
107
|
0
|
0
|
|
|
|
|
if ($redis_server) |
108
|
|
|
|
|
|
|
{ |
109
|
0
|
|
|
|
|
|
my $cmd = $redis_server; |
110
|
0
|
0
|
|
|
|
|
$cmd .= " $bind" if defined($bind); |
111
|
0
|
|
|
|
|
|
$cmd = shellmeta($cmd); |
112
|
0
|
|
|
|
|
|
system "pgrep -f \"$cmd\" >/dev/null 2>&1"; |
113
|
0
|
0
|
|
|
|
|
$result = ($? == 0)? 1: 0; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
print $result; |
116
|
0
|
|
|
|
|
|
return $result; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _info |
120
|
|
|
|
|
|
|
{ |
121
|
0
|
|
|
0
|
|
|
my ($key, $bind) = map(zbx_decode($_), @ARGV); |
122
|
0
|
0
|
|
|
|
|
return "" unless $key; |
123
|
0
|
|
|
|
|
|
my $result = ""; |
124
|
0
|
|
|
|
|
|
my $info = get_info($bind); |
125
|
0
|
0
|
|
|
|
|
$result = $info->{$key} if defined($info->{$key}); |
126
|
0
|
|
|
|
|
|
print $result; |
127
|
0
|
|
|
|
|
|
return $result; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
__END__ |