/[smecontribs]/rpms/smeserver-zabbix-agent/contribs9/smeserver-zabbix-agent-0.1-better_asterisk_monitoring.patch
ViewVC logotype

Annotation of /rpms/smeserver-zabbix-agent/contribs9/smeserver-zabbix-agent-0.1-better_asterisk_monitoring.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Tue Feb 9 23:18:26 2016 UTC (8 years, 8 months ago) by stephdl
Branch: MAIN
CVS Tags: smeserver-zabbix-agent-0_1-53_el6_sme, smeserver-zabbix-agent--, HEAD
* Wed Feb 10 stephane de Labrusse <stephdl@de-labrusse.fr> - 0.1-53.sme
- New rpm for sme9

1 stephdl 1.1 diff -Nur smeserver-zabbix-agent-0.1/root/etc/e-smith/templates/etc/sudoers/00zabbixAgentAlias smeserver-zabbix-agent-0.1_mod/root/etc/e-smith/templates/etc/sudoers/00zabbixAgentAlias
2     --- smeserver-zabbix-agent-0.1/root/etc/e-smith/templates/etc/sudoers/00zabbixAgentAlias 2011-10-26 18:20:16.000000000 +0200
3     +++ smeserver-zabbix-agent-0.1_mod/root/etc/e-smith/templates/etc/sudoers/00zabbixAgentAlias 2011-10-26 18:29:27.000000000 +0200
4     @@ -6,14 +6,6 @@
5     $runasroot .= "\n";
6     $OUT .= 'Cmnd_Alias ZABBIX_AGENT_ROOT = '.$runasroot;
7    
8     -if ( -x '/usr/sbin/asterisk' ){
9     - $OUT.=<<"HERE"
10     -
11     -Cmnd_Alias ZABBIX_AGENT_ASTERISK = /var/lib/zabbix/bin/check_asterisk *
12     -
13     -HERE
14     -}
15     -
16     }
17     Cmnd_Alias ZABBIX_AGENT_MYSQL = /usr/bin/du -s /var/lib/mysql
18    
19     diff -Nur smeserver-zabbix-agent-0.1/root/etc/e-smith/templates/etc/sudoers/30zabbixAgent smeserver-zabbix-agent-0.1_mod/root/etc/e-smith/templates/etc/sudoers/30zabbixAgent
20     --- smeserver-zabbix-agent-0.1/root/etc/e-smith/templates/etc/sudoers/30zabbixAgent 2011-10-26 18:20:16.000000000 +0200
21     +++ smeserver-zabbix-agent-0.1_mod/root/etc/e-smith/templates/etc/sudoers/30zabbixAgent 2011-10-26 18:29:41.000000000 +0200
22     @@ -1,9 +1,2 @@
23     zabbix ALL=(root) NOPASSWD: ZABBIX_AGENT_ROOT
24     zabbix ALL=(mysql) NOPASSWD: ZABBIX_AGENT_MYSQL
25     -{
26     -if ( -x '/usr/sbin/asterisk' ){
27     - $OUT.=<<"HERE"
28     -zabbix ALL=(asterisk) NOPASSWD: ZABBIX_AGENT_ASTERISK
29     -HERE
30     -}
31     -}
32     diff -Nur smeserver-zabbix-agent-0.1/root/etc/e-smith/templates/etc/zabbix/zabbix_agentd.conf/90UserParameters_asterisk smeserver-zabbix-agent-0.1_mod/root/etc/e-smith/templates/etc/zabbix/zabbix_agentd.conf/90UserParameters_asterisk
33     --- smeserver-zabbix-agent-0.1/root/etc/e-smith/templates/etc/zabbix/zabbix_agentd.conf/90UserParameters_asterisk 2011-10-26 18:20:16.000000000 +0200
34     +++ smeserver-zabbix-agent-0.1_mod/root/etc/e-smith/templates/etc/zabbix/zabbix_agentd.conf/90UserParameters_asterisk 2011-10-26 18:30:24.000000000 +0200
35     @@ -1,15 +1,25 @@
36     {
37    
38     if ( -x '/usr/sbin/asterisk' ){
39     + my $login = "";
40     + my $user = ${'zabbix-agent'}{'AsteriskManagerLogin'} || '';
41     + my $pass = ${'zabbix-agent'}{'AsteriskManagerPassword'} || '';
42     + if ($user ne ''){
43     + $login .= "--user=$user";
44     + }
45     + if ($pass ne ''){
46     + $login .= " --secret=$pass";
47     + }
48     $OUT.=<<"HERE"
49     # Type: Agent or Agent (active)
50     -# Key: asterisk[key] where key can be max_latency, sip_peers, iax2_peers, channels, calls, version
51     -# Type of information: Numeric (integer 64bit) or characters (for version)
52     +# Key: asterisk[key] where key can be max_latency, sip_peers, channels, internal_calls,
53     +# outgoing_calls, incoming_calls, external_calls, duration_internal or duration_external
54     +# Type of information: Numeric (integer 64bit)
55     # Units: depends on the key
56     # Custom multiplier: Do not use
57     # Store Value: As is
58    
59     -UserParameter=asterisk[*],/usr/bin/sudo -u asterisk /var/lib/zabbix/bin/check_asterisk_monitoring \$1
60     +UserParameter=asterisk[*],/var/lib/zabbix/bin/check_asterisk $login --what=\$1
61    
62     HERE
63     }
64     diff -Nur smeserver-zabbix-agent-0.1/root/var/lib/zabbix/bin/check_asterisk smeserver-zabbix-agent-0.1_mod/root/var/lib/zabbix/bin/check_asterisk
65     --- smeserver-zabbix-agent-0.1/root/var/lib/zabbix/bin/check_asterisk 2011-10-26 18:20:16.000000000 +0200
66     +++ smeserver-zabbix-agent-0.1_mod/root/var/lib/zabbix/bin/check_asterisk 2011-10-26 18:22:45.000000000 +0200
67     @@ -1,63 +1,210 @@
68     -#!/bin/bash
69     +#!/usr/bin/perl -w
70    
71     -# Asterisk check script
72     -# by Steeve Avoungou Firewall Services
73     +use Asterisk::AMI::Common;
74     +use Getopt::Long;
75    
76     -PATH=$PATH:/usr/sbin:/usr/local/sbin
77     +open STDERR, '>/dev/null';
78    
79     -if [ $# -ne "1" ]; then
80     - echo "Usage:"
81     - echo "$0 <arg>"
82     - echo "Where <arg> can be one of version, sip_peers, iax2_peers, max_latency, channels, calls"
83     - exit 1
84     -fi
85     -
86     -
87     -case "$@" in
88     -
89     - # Show version of asterisk:
90     - version)
91     - echo $(asterisk -rx 'core show version')
92     - ;;
93     -
94     - # Count SIP peers
95     - sip_peers)
96     - echo $(asterisk -rx 'sip show peers'| grep -v 'Name/username' | egrep -v '[[:digit:]] sip peers' | wc -l)
97     - ;;
98     -
99     - # Display the higher latency
100     - max_latency)
101     - max_latency=0
102     - for i in $(asterisk -rx 'sip show peers' | awk '{print $8}' | grep -o '[0-9][0-9]*'); do
103     - if [ "$i" -gt "$max_latency" ]; then
104     - max_latency=$i
105     - fi
106     - done
107     - for i in $(asterisk -rx 'iax2 show peers' | awk '{print $8}' | grep -o '[0-9][0-9]*'); do
108     - if [ "$i" -gt "$max_latency" ]; then
109     - max_latency=$i
110     - fi
111     - done
112     - echo $max_latency
113     - ;;
114     -
115     - # Count IAX2 peers
116     - iax2_peers)
117     - echo $(asterisk -rx 'iax2 show peers' | grep -v 'Name/Username' | egrep -v '[[:digit:]] iax2 peers' | wc -l)
118     - ;;
119     -
120     - # Count number of active channels
121     - channels)
122     - echo $(asterisk -rx "core show channels" | grep 'active channel' | awk '{print $1}')
123     - ;;
124     -
125     - # Count number of active calls
126     - calls)
127     - echo $(asterisk -rx "core show channels" | grep 'active call' | awk '{print $1}')
128     - ;;
129     -
130     - *)
131     - echo 'ZBX_NOTSUPPORTED'
132     - ;;
133     -esac
134     +# Set some default
135     +my $host = '127.0.0.1';
136     +my $port = '5038';
137     +my $user = 'zabbixagent';
138     +my $secret = 'zabbixsecret';
139     +my $what = 'sip_peers';
140     +
141     +GetOptions(
142     + "host=s" => \$host,
143     + "port=s" => \$port,
144     + "user=s" => \$user,
145     + "secret=s" => \$secret,
146     + "what=s" => \$what
147     +);
148     +
149     +our $ast = Asterisk::AMI::Common->new(
150     + PeerAddr => $host,
151     + PeerPort => $port,
152     + Username => $user,
153     + Secret => $secret
154     + );
155     +
156     +die "Unable to connect to asterisk manager" unless ($ast);
157     +
158     +
159     +sub help{
160     + print<<"EOF";
161     +
162     +usage: $0 --host=asterisk.domain.tld --port=5038 --user=manager --secret=azerty --what=sip_peers
163     +
164     +--what can take the following argument:
165     +
166     + * sip_peers: number of connected sip peers
167     + * max_latency: highest latency of connected sip_peers
168     + * channels: total number of active channels
169     + * internal_calls: number of active internal calls
170     + * outgoing_calls: number of active outgoing calls (external)
171     + * incoming_calls: number of active incoming calls (external)
172     + * external_calls: number of external calls (in + out)
173     + * duration_internal: actual highest duration of internal calls
174     + * duration_external: actual highest duration of external calls
175     +
176     +EOF
177     +
178     +
179     +if ($what eq 'sip_peers'){
180     + print get_connected_peers_num('sip');
181     +}
182     +elsif ($what eq 'max_latency'){
183     + print get_max_peer_latency();
184     +}
185     +elsif($what eq 'channels'){
186     + print get_active_channels_num();
187     +}
188     +elsif ($what eq 'internal_calls'){
189     + print get_internal_call_num();
190     +}
191     +elsif ($what eq 'outgoing_calls'){
192     + print get_outgoing_call_num();
193     +}
194     +elsif ($what eq 'incoming_calls'){
195     + print get_incoming_call_num();
196     +}
197     +elsif ($what eq 'external_calls'){
198     + print get_outgoing_call_num() + get_incoming_call_num();
199     +}
200     +elsif ($what eq 'duration_internal'){
201     + print get_max_duration_internal();
202     +}
203     +elsif ($what eq 'duration_external'){
204     + print get_max_duration_external();
205     +}
206     +else{
207     + help();
208     + $ast->disconnect();
209     + exit (1);
210     +}
211     +
212     +$ast->disconnect();
213     +exit(0);
214     +
215     +# Return the number of connected peers for
216     +# the specified protocol (only SIP supporteed for now)
217     +sub get_connected_peers_num{
218     + my $proto = shift;
219     + my $peers;
220     + if ($proto eq 'sip'){
221     + $peers = get_sip_peers();
222     + }
223     + else{
224     + return 'unsupported protocol';
225     + }
226     + my $num = 0;
227     + foreach my $peer (keys %{$peers}){
228     + my $status = $peers->{$peer}->{'Status'};
229     + $num++ if ($status =~ m/^OK/);
230     + }
231     + return $num;
232     +}
233     +
234     +# Return the list of SIP peers (as a hashref)
235     +sub get_sip_peers{
236     + return $ast->sip_peers();
237     +}
238     +
239     +# Return the highest latency of all the peers
240     +sub get_max_peer_latency{
241     + my $peers = get_sip_peers();
242     + my $latency = 0;
243     + foreach my $peer (keys %{$peers}){
244     + my $status = $peers->{$peer}->{'Status'};
245     + $status =~ /\((\d+)\sms\)/;
246     + $latency = $1 if ($1 > $latency);
247     + }
248     + return $latency;
249     +}
250     +
251     +# Return channels list as a hashref
252     +sub get_channels(){
253     + return $ast->channels();
254     +}
255     +
256     +# Return the number of channels
257     +sub get_active_channels_num{
258     + my $channels = get_channels();
259     + my $num = 0;
260     + foreach my $chan (keys %{$channels}){
261     + $num++;
262     + }
263     + return $num;
264     +}
265     +
266     +# Return the number of active channels
267     +sub get_up_channels_num{
268     + my $channels = get_channels();
269     + my $num = 0;
270     + foreach my $chan (keys %{$channels}){
271     + my $status = $channels->{$chan}->{'State'};
272     + $num++ if ($status eq 'Up');
273     + }
274     + return $num;
275     +}
276     +
277     +# Return the number of outgoing calls
278     +sub get_outgoing_call_num{
279     + my $channels = get_channels();
280     + my $num = 0;
281     + foreach my $chan (keys %{$channels}){
282     + my $context = $channels->{$chan}->{'Context'};
283     + my $status = $channels->{$chan}->{'State'};
284     + $num++ if ($context eq 'macro-dialout-trunk' and $status eq 'Up');
285     + }
286     + return $num;
287     +}
288     +
289     +# Return the number of incoming calls
290     +sub get_incoming_call_num{
291     + my $channels = get_channels();
292     + my $num = 0;
293     + foreach my $chan (keys %{$channels}){
294     + my $context = $channels->{$chan}->{'Context'};
295     + my $status = $channels->{$chan}->{'State'};
296     + $num++ if ($context =~ /^from\-(trunk|pstn|zaptel|dahdi)/ and $status eq 'Up');
297     + }
298     + return $num;
299     +}
300     +
301     +# Return the number of internal calls
302     +sub get_internal_call_num{
303     + my $channels = get_channels();
304     + my $num = 0;
305     + foreach my $chan (keys %{$channels}){
306     + my $context = $channels->{$chan}->{'Context'};
307     + my $status = $channels->{$chan}->{'State'};
308     + $num++ if (($context eq 'macro-dial' or $context eq 'from-internal') and $status eq 'Up');
309     + }
310     + return $num
311     +}
312     +
313     +# Return the max duration of current internal calls
314     +sub get_max_duration_internal{
315     + my $channels = get_channels();
316     + my $max = 0;
317     + foreach my $chan (keys %{$channels}){
318     + my $dur = $channels->{$chan}->{'Seconds'};
319     + my $context = $channels->{$chan}->{'Context'};
320     + $max = $dur if (($context eq 'macro-dial' or $context eq 'from-internal') and $dur > $max);
321     + }
322     + return $max
323     +}
324     +
325     +# Return the max duration of current external calls (in or out)
326     +sub get_max_duration_external{
327     + my $channels = get_channels();
328     + my $max = 0;
329     + foreach my $chan (keys %{$channels}){
330     + my $dur = $channels->{$chan}->{'Seconds'};
331     + my $context = $channels->{$chan}->{'Context'};
332     + $max = $dur if (($context eq 'macro-dialout-trunk' or $context =~ /^from\-(trunk|pstn|zaptel|dahdi)/) and $dur > $max);
333     + }
334     + return $max
335     +}
336    

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed