File: 20_check_snmp_int_avaid_huge_amount_of_regex

package info (click to toggle)
nagios-snmp-plugins 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,244 kB
  • sloc: perl: 7,453; sh: 309; makefile: 50
file content (93 lines) | stat: -rw-r--r-- 6,545 bytes parent folder | download | duplicates (2)
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
90
91
92
93
From c591f7d56378cbb40f1c3c23cbf23a8669a45730 Mon Sep 17 00:00:00 2001
From: kwork-er <88452982+kwork-er@users.noreply.github.com>
Date: Thu, 5 Aug 2021 21:53:43 +0200
Subject: [PATCH] Update check_snmp_int.pl

Effectively reverting commit 9f9b15a926d8795935b54626dc3ab9e5becb2763 and doing it in a different way that avoids adding huge amounts of regex, that may not run on older systems.
Removed the added " =~ s/\./_/r ", instead replacing the dots (.) in the regex that was meant for it in the first place -> line 967.
---
 plugins/check_snmp_int.pl | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/plugins/check_snmp_int.pl b/plugins/check_snmp_int.pl
index 271cfbc..71f8d14 100755
--- a/plugins/check_snmp_int.pl
+++ b/plugins/check_snmp_int.pl
@@ -964,7 +964,7 @@ sub check_options {
     }
 
     # Get rid of special caracters for performance in description
-    $descr[$i] =~ s/'\/\(\)/_/g;
+    $descr[$i] =~ s/['\/\(\).]/_/g;
     if (($int_status == $ok_val) || (defined($o_down) && $int_status == 2) || (defined($o_dormant) && $int_status == 5))
     {
         $num_ok++;
@@ -979,12 +979,12 @@ sub check_options {
                     $warn_factor /= $speed_real;
                     $warn_factor *= 100;    # now turn into displayed % : 0,1 = 10%
                 }
-                $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_in_prct'=";
+                $perf_out .= "'" . $descr[$i] . "_in_prct'=";
                 $perf_out .= sprintf("%.0f", $checkperf_out_raw[0] * 800 / $speed_real) . "%;";
                 $perf_out .= ($o_warn[0] != 0) ? sprintf("%.0f", $o_warn[0] * $warn_factor) . ";" : ";";
                 $perf_out .= ($o_crit[0] != 0) ? sprintf("%.0f", $o_crit[0] * $warn_factor) . ";" : ";";
                 $perf_out .= "0;100 ";
-                $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_out_prct'=";
+                $perf_out .= "'" . $descr[$i] . "_out_prct'=";
                 $perf_out .= sprintf("%.0f", $checkperf_out_raw[1] * 800 / $speed_real) . "%;";
                 $perf_out .= ($o_warn[1] != 0) ? sprintf("%.0f", $o_warn[1] * $warn_factor) . ";" : ";";
                 $perf_out .= ($o_crit[1] != 0) ? sprintf("%.0f", $o_crit[1] * $warn_factor) . ";" : ";";
@@ -1000,12 +1000,12 @@ sub check_options {
                     } else {                   # just convert from K|M|G bps
                         $warn_factor = (defined($o_meg)) ? 1000000 : (defined($o_gig)) ? 1000000000 : 1000;
                     }
-                    $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_in_bps'=";
+                    $perf_out .= "'" . $descr[$i] . "_in_bps'=";
                     $perf_out .= sprintf("%.0f", $checkperf_out_raw[0] * 8) . ";";
                     $perf_out .= ($o_warn[0] != 0) ? $o_warn[0] * $warn_factor . ";" : ";";
                     $perf_out .= ($o_crit[0] != 0) ? $o_crit[0] * $warn_factor . ";" : ";";
                     $perf_out .= "0;" . $speed_real . " ";
-                    $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_out_bps'=";
+                    $perf_out .= "'" . $descr[$i] . "_out_bps'=";
                     $perf_out .= sprintf("%.0f", $checkperf_out_raw[1] * 8) . ";";
                     $perf_out .= ($o_warn[1] != 0) ? $o_warn[1] * $warn_factor . ";" : ";";
                     $perf_out .= ($o_crit[1] != 0) ? $o_crit[1] * $warn_factor . ";" : ";";
@@ -1017,29 +1017,29 @@ sub check_options {
                     } else {                   # just convert from K|M|G bps
                         $warn_factor = (defined($o_meg)) ? 1048576 : (defined($o_gig)) ? 1073741824 : 1024;
                     }
-                    $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_in_Bps'=" . sprintf("%.0f", $checkperf_out_raw[0]) . ";";
+                    $perf_out .= "'" . $descr[$i] . "_in_Bps'=" . sprintf("%.0f", $checkperf_out_raw[0]) . ";";
                     $perf_out .= ($o_warn[0] != 0) ? $o_warn[0] * $warn_factor . ";" : ";";
                     $perf_out .= ($o_crit[0] != 0) ? $o_crit[0] * $warn_factor . ";" : ";";
                     $perf_out .= "0;" . $speed_real / 8 . " ";
-                    $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_out_Bps'=" . sprintf("%.0f", $checkperf_out_raw[1]) . ";";
+                    $perf_out .= "'" . $descr[$i] . "_out_Bps'=" . sprintf("%.0f", $checkperf_out_raw[1]) . ";";
                     $perf_out .= ($o_warn[1] != 0) ? $o_warn[1] * $warn_factor . ";" : ";";
                     $perf_out .= ($o_crit[1] != 0) ? $o_crit[1] * $warn_factor . ";" : ";";
                     $perf_out .= "0;" . $speed_real / 8 . " ";
                 }
             }
         } else {    # output in octet counter
-            $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_in_octet'=" . $$result{ $oid_perf_inoct[$i] } . "c ";
-            $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_out_octet'=" . $$result{ $oid_perf_outoct[$i] } . "c ";
+            $perf_out .= "'" . $descr[$i] . "_in_octet'=" . $$result{ $oid_perf_inoct[$i] } . "c ";
+            $perf_out .= "'" . $descr[$i] . "_out_octet'=" . $$result{ $oid_perf_outoct[$i] } . "c ";
         }
         if (defined($o_perfe)) {
-            $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_in_error'=" . $$result{ $oid_perf_inerr[$i] } . "c ";
-            $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_in_discard'=" . $$result{ $oid_perf_indisc[$i] } . "c ";
-            $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_out_error'=" . $$result{ $oid_perf_outerr[$i] } . "c ";
-            $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_out_discard'=" . $$result{ $oid_perf_outdisc[$i] } . "c ";
+            $perf_out .= "'" . $descr[$i] . "_in_error'=" . $$result{ $oid_perf_inerr[$i] } . "c ";
+            $perf_out .= "'" . $descr[$i] . "_in_discard'=" . $$result{ $oid_perf_indisc[$i] } . "c ";
+            $perf_out .= "'" . $descr[$i] . "_out_error'=" . $$result{ $oid_perf_outerr[$i] } . "c ";
+            $perf_out .= "'" . $descr[$i] . "_out_discard'=" . $$result{ $oid_perf_outdisc[$i] } . "c ";
         }
         if (defined($o_perfs)) {
 	    $speed_real = "" unless (defined($speed_real));
-            $perf_out .= "'" . $descr[$i] =~ s/\./_/r . "_speed_bps'=" . $speed_real . " ";
+            $perf_out .= "'" . $descr[$i] . "_speed_bps'=" . $speed_real . " ";
         }
         if (defined($o_weather) && $usable_data == 1) {
             $perf_out .= "in=" . sprintf("%.0f", $checkperf_out_raw[0]) . ";;;0;" . sprintf("%.0f", $speed_real / 8) . " ";