Bonjour à tous,
Étant débutant dans la programmation, je suis confronté à un problème. Je dois mettre en place une supervision de QoS entre certaines machines du réseau, avec des seuils prédéfinis (avec le logiciel de supervision Centreon).
J'utilise actuellement un script qui effectue un contrôle du débit (c'est à dire que les seuils associés au script se font uniquement sur le débit).
Ce script fait appel à la commande "iperf", qui permet d'obtenir en sortie : 1.05 Mbits/sec 0.064 ms 0/ 893 (0%), nous avons en premier le débit, puis la gigue et enfin la perte de paquets.
Or ce que je voudrais, c'est le même script mais qui contrôle la perte de paquet. Ayant tenté de modifier le code sous la section "open", je ne m'y retrouve pas, j'ai également effectué diverses recherches ("perl seuil sortie commande" ou des équivalents), mais je n'ai pas trouvé mon bonheur :/
Par rapport à la sortie de la commande (1.05 Mbits/sec 0.064 ms 0/ 893 (0%)),
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 use strict; $ENV{'PATH'}=''; $ENV{'BASH_ENV'}=''; $ENV{'ENV'}=''; my ($target,$exit); #my $iperf = "c:\\temp\\iperf.exe"; my $iperf = "/usr/local/bin/iperf"; if ($#ARGV+1 !=3) { usage(); exit; } elsif (! -f "$iperf") { print "didn't find iperf here '$iperf'.\n"; exit; } else { $target = $ARGV[0]; } our ($mtu,$connect_ok,$speed,$unit); $connect_ok = 0; $speed = "UNKNOWN"; my ($maxwarn,$maxcrit,$minwarn,$mincrit); $mincrit = $ARGV[1]; if ($mincrit =~ m/([0-9].+):([0-9].+)/) { $mincrit = $1; $maxcrit = $2; } $minwarn = $ARGV[2]; if ($minwarn =~ m/([0-9].+):([0-9].+)/) { $minwarn = $1; $maxwarn = $2; } #print "DEBUG: $iperf -c $target -m\n"; open(OUT, "$iperf -c $target -m -u|"); while (<OUT>) { chomp; #print "DEBUG: '$_'\n"; if (m/TCP window size: ([0-9\.].+) (\w)/) { $mtu = "$1 $2"; } elsif (m/connected with/) { $connect_ok = 1; } elsif (m/^\[.*\] [0-9-\.].+ sec.*[0-9\.] .Bytes\s*([0-9].*) (.*)$/) { #print "DEBUG: '$_' ; '$1', '$2' \n"; $speed = $1; $unit = $2; } } if ($connect_ok == 0) { print "NOK: iperf didn't connect to '$target'.\n"; $exit = 2; } elsif ($speed<$mincrit) { print "Critical: iperf speed of '$target': $speed ($unit) < $mincrit.\n";$exit=2; } elsif (defined($maxcrit) && $speed > $maxcrit) { print "Critical: iperf speed of '$target': $speed ($unit) > $maxcrit.\n";$exit=2; } elsif ($speed < $minwarn) { print "Warning: iperf speed of '$target': $speed ($unit) < $minwarn.\n";$exit=1; } elsif (defined($maxwarn) && $speed > $maxwarn) { print "Warning: iperf speed of '$target': $speed ($unit) > $maxwarn.\n";$exit=2; } else { #print "OK: iperf returns $speed $unit (wsize $mtu).\n"; $exit = 0; print "OK: iperf returns (débit,gigue,perte) $speed $unit.\n"; $exit = 0; } sub usage { print <<EOL $0 <target host> "Critical speed" "Warning speed": this plugin returns iperf usage examples: $0 <host> 10 15: critical if speed under 10 units $0 <host> 10 15:50: warning if speed out of 15:50 units $0 <host> 10:100 15:90 $0 <host> 10:40 15:90 EOL } exit $exit;
$speed = 1.05 Mbits/sec 0.064 ms 0/ 893
$unit = (0%)
Si vous avez des pistes pour m'orienter sur ce que je dois modifier du code, je suis preneur !
Merci !
Cordialement,
Soupap.
Partager