diff options
| author | Sven Nierlein <sven@nierlein.de> | 2014-01-20 00:54:34 +0100 |
|---|---|---|
| committer | Sven Nierlein <sven@nierlein.de> | 2014-01-20 00:54:34 +0100 |
| commit | b418181dfe80dd75169b6e8a619ac1932155dea2 (patch) | |
| tree | cad9c0ae0eae8e800cfff60555ead06ad33c6856 /t/Monitoring-Plugin-Performance.t | |
| parent | 1cd8d1c52cbd47121f344c4074aec84653f412ce (diff) | |
| download | monitoring-plugin-perl-b418181dfe80dd75169b6e8a619ac1932155dea2.tar.gz | |
renamed module into Monitoring::Plugin
since the complete monitoring team has been renamed, we
also rename this module.
Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 't/Monitoring-Plugin-Performance.t')
| -rw-r--r-- | t/Monitoring-Plugin-Performance.t | 357 |
1 files changed, 357 insertions, 0 deletions
diff --git a/t/Monitoring-Plugin-Performance.t b/t/Monitoring-Plugin-Performance.t new file mode 100644 index 0000000..bedb2e2 --- /dev/null +++ b/t/Monitoring-Plugin-Performance.t | |||
| @@ -0,0 +1,357 @@ | |||
| 1 | |||
| 2 | use warnings; | ||
| 3 | use strict; | ||
| 4 | use Test::More; | ||
| 5 | use Monitoring::Plugin::Functions; | ||
| 6 | Monitoring::Plugin::Functions::_fake_exit(1); | ||
| 7 | |||
| 8 | |||
| 9 | my (@p, $p); | ||
| 10 | my @test = ( | ||
| 11 | { | ||
| 12 | perfoutput => "/=382MB;15264;15269;0;32768", label => '/', rrdlabel => 'root', value => 382, uom => 'MB', warning => 15264, critical => 15269, min => 0, max => 32768, clean_label => "root", | ||
| 13 | }, { | ||
| 14 | perfoutput => "/var=218MB;9443;9448", label => '/var', rrdlabel => 'var', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => "var", | ||
| 15 | }, { | ||
| 16 | perfoutput => '/var/long@:-/filesystem/name/and/bad/chars=218MB;9443;9448', label => '/var/long@:-/filesystem/name/and/bad/chars', rrdlabel => 'var_long____filesys', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => 'var_long____filesystem_name_and_bad_chars', | ||
| 17 | }, { | ||
| 18 | perfoutput => "'page file'=36%;80;90;", | ||
| 19 | expected_perfoutput => "'page file'=36%;80;90", | ||
| 20 | label => 'page file', | ||
| 21 | rrdlabel => 'page_file', | ||
| 22 | value => '36', | ||
| 23 | uom => '%', | ||
| 24 | warning => 80, | ||
| 25 | critical => 90, | ||
| 26 | min => undef, | ||
| 27 | max => undef, | ||
| 28 | clean_label => 'page_file', | ||
| 29 | }, { | ||
| 30 | perfoutput => "'data'=5;;;;", | ||
| 31 | expected_perfoutput => "data=5;;", | ||
| 32 | label => 'data', | ||
| 33 | rrdlabel => 'data', | ||
| 34 | value => 5, | ||
| 35 | uom => "", | ||
| 36 | warning => undef, | ||
| 37 | critical => undef, | ||
| 38 | min => undef, | ||
| 39 | max => undef, | ||
| 40 | clean_label => 'data', | ||
| 41 | }, | ||
| 42 | ); | ||
| 43 | |||
| 44 | plan tests => (11 * scalar @test) + 176; | ||
| 45 | |||
| 46 | use_ok('Monitoring::Plugin::Performance'); | ||
| 47 | diag "\nusing Monitoring::Plugin::Performance revision ". $Monitoring::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; | ||
| 48 | |||
| 49 | # Round-trip tests | ||
| 50 | for my $t (@test) { | ||
| 51 | # Parse to components | ||
| 52 | ($p) = Monitoring::Plugin::Performance->parse_perfstring($t->{perfoutput}); | ||
| 53 | is ($p->value, $t->{value}, "value okay $t->{value}"); | ||
| 54 | is ($p->label, $t->{label}, "label okay $t->{label}"); | ||
| 55 | is ($p->uom, $t->{uom}, "uom okay $t->{uom}"); | ||
| 56 | |||
| 57 | # Construct from components | ||
| 58 | my @construct = qw(label value uom warning critical min max); | ||
| 59 | $p = Monitoring::Plugin::Performance->new(map { $_ => $t->{$_} } @construct); | ||
| 60 | my $expected_perfoutput = $t->{perfoutput}; | ||
| 61 | if (exists $t->{expected_perfoutput}) { | ||
| 62 | $expected_perfoutput = $t->{expected_perfoutput}; | ||
| 63 | }; | ||
| 64 | is($p->perfoutput, $expected_perfoutput, "perfoutput okay ($expected_perfoutput)"); | ||
| 65 | # Check threshold accessor | ||
| 66 | foreach my $type (qw(warning critical)) { | ||
| 67 | if (! defined $t->{$type}) { | ||
| 68 | isnt( $p->threshold->$type->is_set, "threshold $type not set"); | ||
| 69 | } else { | ||
| 70 | is($p->threshold->$type->end, $t->{$type}, "threshold $type okay ($t->{$type})"); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | is($p->rrdlabel, $t->{rrdlabel}, "rrdlabel okay"); | ||
| 74 | is($p->clean_label, $t->{clean_label}, "clean_label okay" ); | ||
| 75 | |||
| 76 | # Construct using threshold | ||
| 77 | @construct = qw(label value uom min max); | ||
| 78 | $p = Monitoring::Plugin::Performance->new( | ||
| 79 | map({ $_ => $t->{$_} } @construct), | ||
| 80 | threshold => Monitoring::Plugin::Threshold->set_thresholds(warning => $t->{warning}, critical => $t->{critical}), | ||
| 81 | ); | ||
| 82 | is($p->perfoutput, $expected_perfoutput, "perfoutput okay ($expected_perfoutput)"); | ||
| 83 | # Check warning/critical accessors | ||
| 84 | foreach my $type (qw(warning critical)) { | ||
| 85 | if (! defined $t->{$type}) { | ||
| 86 | isnt( $p->threshold->$type->is_set, "threshold $type not set"); | ||
| 87 | } else { | ||
| 88 | is($p->threshold->$type->end, $t->{$type}, "threshold $type okay ($t->{$type})"); | ||
| 89 | } | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | # Test multiple parse_perfstrings | ||
| 95 | @p = Monitoring::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); | ||
| 96 | cmp_ok( $p[0]->label, 'eq', "/", "label okay"); | ||
| 97 | cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay"); | ||
| 98 | cmp_ok( $p[0]->value, '==', 382, "value okay"); | ||
| 99 | cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay"); | ||
| 100 | cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay"); | ||
| 101 | cmp_ok( $p[0]->threshold->critical->end, "==", 15269, "crit okay"); | ||
| 102 | ok(! defined $p[0]->min, "min undef"); | ||
| 103 | ok(! defined $p[0]->max, "max undef"); | ||
| 104 | |||
| 105 | cmp_ok( $p[1]->label, 'eq', "/var", "label okay"); | ||
| 106 | cmp_ok( $p[1]->rrdlabel, 'eq', "var", "rrd label okay"); | ||
| 107 | cmp_ok( $p[1]->value, '==', 218, "value okay"); | ||
| 108 | cmp_ok( $p[1]->uom, 'eq', "MB", "uom okay"); | ||
| 109 | cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay"); | ||
| 110 | cmp_ok( $p[1]->threshold->critical->end, "==", 9448, "crit okay"); | ||
| 111 | |||
| 112 | @p = Monitoring::Plugin::Performance->parse_perfstring("rubbish"); | ||
| 113 | ok( ! @p, "Errors correctly"); | ||
| 114 | ok( ! Monitoring::Plugin::Performance->parse_perfstring(""), "Errors on empty string"); | ||
| 115 | |||
| 116 | |||
| 117 | |||
| 118 | # Check 1 bad with 1 good format output | ||
| 119 | @p = Monitoring::Plugin::Performance->parse_perfstring("rta=&391ms;100,200;500,034;0; pl=0%;20;60 "); | ||
| 120 | is( scalar @p, 1, "One bad piece of data - only one returned" ); | ||
| 121 | is( $p[0]->label, "pl", "label okay for different numeric"); | ||
| 122 | is( $p[0]->value, 0, "value okay"); | ||
| 123 | is( $p[0]->uom, "%", "uom okay"); | ||
| 124 | ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); | ||
| 125 | is( $p[0]->threshold->warning, "20", "warn okay"); | ||
| 126 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
| 127 | is( $p[0]->threshold->critical, "60", "warn okay"); | ||
| 128 | |||
| 129 | # Same as above, but order swapped | ||
| 130 | @p = Monitoring::Plugin::Performance->parse_perfstring(" pl=0%;20;60 rta=&391ms;100,200;500,034;0; "); | ||
| 131 | is( scalar @p, 1, "One bad piece of data - only one returned" ); | ||
| 132 | is( $p[0]->label, "pl", "label okay for different numeric"); | ||
| 133 | is( $p[0]->value, 0, "value okay"); | ||
| 134 | is( $p[0]->uom, "%", "uom okay"); | ||
| 135 | ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); | ||
| 136 | is( $p[0]->threshold->warning, "20", "warn okay"); | ||
| 137 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
| 138 | is( $p[0]->threshold->critical, "60", "warn okay"); | ||
| 139 | |||
| 140 | |||
| 141 | |||
| 142 | |||
| 143 | @p = Monitoring::Plugin::Performance->parse_perfstring( | ||
| 144 | "time=0.001229s;0.000000;0.000000;0.000000;10.000000"); | ||
| 145 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); | ||
| 146 | cmp_ok( $p[0]->value, "==", 0.001229, "value okay"); | ||
| 147 | cmp_ok( $p[0]->uom, "eq", "s", "uom okay"); | ||
| 148 | ok( $p[0]->threshold->warning->is_set, "warn okay"); | ||
| 149 | ok( $p[0]->threshold->critical->is_set, "crit okay"); | ||
| 150 | |||
| 151 | |||
| 152 | |||
| 153 | @p = Monitoring::Plugin::Performance->parse_perfstring( | ||
| 154 | "load1=0.000;5.000;9.000;0; load5=0.000;5.000;9.000;0; load15=0.000;5.000;9.000;0;"); | ||
| 155 | cmp_ok( $p[0]->label, "eq", "load1", "label okay"); | ||
| 156 | cmp_ok( $p[0]->value, "eq", "0", "value okay with 0 as string"); | ||
| 157 | cmp_ok( $p[0]->uom, "eq", "", "uom empty"); | ||
| 158 | cmp_ok( $p[0]->threshold->warning, "eq", "5", "warn okay"); | ||
| 159 | cmp_ok( $p[0]->threshold->critical, "eq", "9", "crit okay"); | ||
| 160 | cmp_ok( $p[1]->label, "eq", "load5", "label okay"); | ||
| 161 | cmp_ok( $p[2]->label, "eq", "load15", "label okay"); | ||
| 162 | |||
| 163 | @p = Monitoring::Plugin::Performance->parse_perfstring( "users=4;20;50;0" ); | ||
| 164 | cmp_ok( $p[0]->label, "eq", "users", "label okay"); | ||
| 165 | cmp_ok( $p[0]->value, "==", 4, "value okay"); | ||
| 166 | cmp_ok( $p[0]->uom, "eq", "", "uom empty"); | ||
| 167 | cmp_ok( $p[0]->threshold->warning, 'eq', "20", "warn okay"); | ||
| 168 | cmp_ok( $p[0]->threshold->critical, 'eq', "50", "crit okay"); | ||
| 169 | |||
| 170 | @p = Monitoring::Plugin::Performance->parse_perfstring( "users=4;20;50;0\n" ); | ||
| 171 | ok( @p, "parse correctly with linefeed at end (nagiosgraph)"); | ||
| 172 | |||
| 173 | @p = Monitoring::Plugin::Performance->parse_perfstring( | ||
| 174 | "time=0.215300s;5.000000;10.000000;0.000000 size=426B;;;0" ); | ||
| 175 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); | ||
| 176 | cmp_ok( $p[0]->value, "eq", "0.2153", "value okay"); | ||
| 177 | cmp_ok( $p[0]->uom, "eq", "s", "uom okay"); | ||
| 178 | cmp_ok( $p[0]->threshold->warning, 'eq', "5", "warn okay"); | ||
| 179 | cmp_ok( $p[0]->threshold->critical, 'eq', "10", "crit okay"); | ||
| 180 | cmp_ok( $p[1]->label, "eq", "size", "label okay"); | ||
| 181 | cmp_ok( $p[1]->value, "==", 426, "value okay"); | ||
| 182 | cmp_ok( $p[1]->uom, "eq", "B", "uom okay"); | ||
| 183 | ok( ! $p[1]->threshold->warning->is_set, "warn okay"); | ||
| 184 | ok( ! $p[1]->threshold->critical->is_set, "crit okay"); | ||
| 185 | |||
| 186 | # Edge cases | ||
| 187 | @p = Monitoring::Plugin::Performance->parse_perfstring("/home/a-m=0;0;0 shared-folder:big=20 12345678901234567890=20"); | ||
| 188 | cmp_ok( $p[0]->rrdlabel, "eq", "home_a_m", "changing / to _"); | ||
| 189 | ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); | ||
| 190 | cmp_ok( $p[1]->rrdlabel, "eq", "shared_folder_big", "replacing bad characters"); | ||
| 191 | cmp_ok( $p[2]->rrdlabel, "eq", "1234567890123456789", "shortening rrd label"); | ||
| 192 | |||
| 193 | # turn off fake_exit and enable use_die so we pick up on errors via plugin_die | ||
| 194 | Monitoring::Plugin::Functions::_use_die(1); | ||
| 195 | Monitoring::Plugin::Functions::_fake_exit(0); | ||
| 196 | |||
| 197 | @p = Monitoring::Plugin::Performance->parse_perfstring("time=0.002722s;0.000000;0.000000;0.000000;10.000000"); | ||
| 198 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); | ||
| 199 | cmp_ok( $p[0]->value, "eq", "0.002722", "value okay"); | ||
| 200 | cmp_ok( $p[0]->uom, "eq", "s", "uom okay"); | ||
| 201 | ok( defined $p[0]->threshold->warning->is_set, "Warning range has been set"); | ||
| 202 | ok( defined $p[0]->threshold->critical->is_set, "Critical range has been set"); | ||
| 203 | # The two below used to be cmp_ok, but Test::More 0.86 appears to have a problem with a stringification | ||
| 204 | # of 0. See http://rt.cpan.org/Ticket/Display.html?id=41109 | ||
| 205 | # We need to force stringification for test. See RT 57709 | ||
| 206 | is( $p[0]->threshold->warning."", "0", "warn okay"); | ||
| 207 | is( $p[0]->threshold->critical."", "0", "crit okay"); | ||
| 208 | |||
| 209 | @p = Monitoring::Plugin::Performance->parse_perfstring("pct_used=73.7%;90;95"); | ||
| 210 | cmp_ok( $p[0]->label, "eq", "pct_used", "label okay"); | ||
| 211 | cmp_ok( $p[0]->value, "eq", "73.7", "value okay"); | ||
| 212 | cmp_ok( $p[0]->uom, "eq", "%", "uom okay"); | ||
| 213 | ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set"); | ||
| 214 | ok( defined eval { $p[0]->threshold->critical->is_set }, "Critical range has been set"); | ||
| 215 | cmp_ok( $p[0]->threshold->warning, 'eq', "90", "warn okay"); | ||
| 216 | cmp_ok( $p[0]->threshold->critical, 'eq', "95", "crit okay"); | ||
| 217 | |||
| 218 | # Check ranges are parsed correctly | ||
| 219 | @p = Monitoring::Plugin::Performance->parse_perfstring("availability=93.8%;90:99;"); | ||
| 220 | is( $p[0]->label, "availability", "label okay"); | ||
| 221 | is( $p[0]->value, "93.8", "value okay"); | ||
| 222 | is( $p[0]->uom, "%", "uom okay"); | ||
| 223 | ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set"); | ||
| 224 | is( $p[0]->threshold->critical->is_set, 0, "Critical range has not been set"); | ||
| 225 | is( $p[0]->threshold->warning, "90:99", "warn okay"); | ||
| 226 | |||
| 227 | # Check that negative values are parsed correctly in value and ranges | ||
| 228 | @p = Monitoring::Plugin::Performance->parse_perfstring("offset=-0.004476s;-60.000000:-5;-120.000000:-3;"); | ||
| 229 | is( $p[0]->label, "offset", "label okay"); | ||
| 230 | is( $p[0]->value, "-0.004476", "value okay"); | ||
| 231 | is( $p[0]->uom, "s", "uom okay"); | ||
| 232 | ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set"); | ||
| 233 | ok( defined eval { $p[0]->threshold->critical->is_set }, "Critical range has been set"); | ||
| 234 | is( $p[0]->threshold->warning, "-60:-5", "warn okay"); | ||
| 235 | is( $p[0]->threshold->critical, "-120:-3", "crit okay"); | ||
| 236 | |||
| 237 | # Check infinity values are okay | ||
| 238 | @p = Monitoring::Plugin::Performance->parse_perfstring("salary=52GBP;~:23.5;45.2:"); | ||
| 239 | is( $p[0]->label, "salary", "label okay"); | ||
| 240 | is( $p[0]->value, "52", "value okay"); | ||
| 241 | is( $p[0]->uom, "GBP", "uom okay"); | ||
| 242 | ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set"); | ||
| 243 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
| 244 | is( $p[0]->threshold->warning, "~:23.5", "warn okay"); | ||
| 245 | is( $p[0]->threshold->critical, "45.2:", "warn okay"); | ||
| 246 | |||
| 247 | # Check scientific notation | ||
| 248 | @p = Monitoring::Plugin::Performance->parse_perfstring("offset=1.120567322e-05"); | ||
| 249 | is( $p[0]->label, "offset", "label okay for scientific notation"); | ||
| 250 | is( $p[0]->value, 1.120567322e-05, "value okay"); | ||
| 251 | is( $p[0]->uom, "", "uom okay"); | ||
| 252 | ok( ! $p[0]->threshold->warning->is_set, "Warning range has not been set"); | ||
| 253 | ok( ! $p[0]->threshold->critical->is_set, "Critical range has not been set"); | ||
| 254 | |||
| 255 | |||
| 256 | # Check scientific notation with warnings and criticals | ||
| 257 | @p = Monitoring::Plugin::Performance->parse_perfstring("offset=-1.120567322e-05unit;-1.1e-05:1.0e-03;4.3e+02:4.3e+25"); | ||
| 258 | is( $p[0]->label, "offset", "label okay for scientific notation in warnings and criticals"); | ||
| 259 | is( $p[0]->value, -1.120567322e-05, "value okay"); | ||
| 260 | is( $p[0]->uom, "unit", "uom okay"); | ||
| 261 | ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); | ||
| 262 | is( $p[0]->threshold->warning, "-1.1e-05:0.001", "warn okay"); | ||
| 263 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
| 264 | is( $p[0]->threshold->critical, "430:4.3e+25", "warn okay"); | ||
| 265 | |||
| 266 | |||
| 267 | |||
| 268 | # Check different collation with commas instead of periods | ||
| 269 | @p = Monitoring::Plugin::Performance->parse_perfstring("rta=1,391ms;100,200;500,034;0; pl=0%;20;60;;"); | ||
| 270 | is( $p[0]->label, "rta", "label okay for numeric with commas instead of periods"); | ||
| 271 | is( $p[0]->value, 1.391, "value okay"); | ||
| 272 | is( $p[0]->uom, "ms", "uom okay"); | ||
| 273 | ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); | ||
| 274 | is( $p[0]->threshold->warning, "100.2", "warn okay"); | ||
| 275 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
| 276 | is( $p[0]->threshold->critical, "500.034", "warn okay"); | ||
| 277 | is( $p[1]->label, "pl", "label okay for different numeric"); | ||
| 278 | is( $p[1]->value, 0, "value okay"); | ||
| 279 | is( $p[1]->uom, "%", "uom okay"); | ||
| 280 | ok( $p[1]->threshold->warning->is_set, "Warning range has been set"); | ||
| 281 | is( $p[1]->threshold->warning, "20", "warn okay"); | ||
| 282 | is( $p[1]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
| 283 | is( $p[1]->threshold->critical, "60", "warn okay"); | ||
| 284 | |||
| 285 | |||
| 286 | # Another set of comma separated stuff | ||
| 287 | @p = Monitoring::Plugin::Performance->parse_perfstring("offset=-0,023545s;60,000000;120,000000;"); | ||
| 288 | is( $p[0]->label, "offset", "label okay for numeric with commas instead of periods"); | ||
| 289 | is( $p[0]->value, -0.023545, "value okay"); | ||
| 290 | is( $p[0]->uom, "s", "uom okay"); | ||
| 291 | is( $p[0]->threshold->warning->is_set, 1, "Warning range has been set"); | ||
| 292 | is( $p[0]->threshold->warning, 60, "warn okay"); | ||
| 293 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
| 294 | is( $p[0]->threshold->critical, 120, "warn okay"); | ||
| 295 | |||
| 296 | # Some values with funny commas | ||
| 297 | @p = Monitoring::Plugin::Performance->parse_perfstring("time=1800,600,300,0,3600 other=45.6"); | ||
| 298 | is( $p[0]->label, "other", "Ignored time=1800,600,300,0,3600, but allowed other=45.6"); | ||
| 299 | is( $p[0]->value, 45.6, "value okay"); | ||
| 300 | is( $p[0]->uom, "", "uom okay"); | ||
| 301 | |||
| 302 | |||
| 303 | # Test labels with spaces (returned by nsclient++) | ||
| 304 | @p = Monitoring::Plugin::Performance->parse_perfstring("'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 'D:\ Label: Serial Number XA22aa2e'=8015MB;16388;18436;1;2048"); | ||
| 305 | is( $p[0]->label, "C:\ Label: Serial Number bc22aa2e"); | ||
| 306 | is( $p[0]->rrdlabel, "C__Label___Serial_N"); | ||
| 307 | is( $p[0]->value, 8015, "value okay"); | ||
| 308 | is( $p[0]->uom, "MB", "uom okay"); | ||
| 309 | is( $p[0]->threshold->warning->end, 16387, "warn okay"); | ||
| 310 | is( $p[0]->threshold->critical->end, 18435, "crit okay"); | ||
| 311 | is( $p[0]->min, 0, "min ok"); | ||
| 312 | is( $p[0]->max, 20484, "max ok"); | ||
| 313 | |||
| 314 | is( $p[1]->label, "D:\ Label: Serial Number XA22aa2e", "label okay"); | ||
| 315 | is( $p[1]->rrdlabel, "D__Label__Serial_Nu", "rrd label okay"); | ||
| 316 | is( $p[1]->value, 8015, "value okay"); | ||
| 317 | is( $p[1]->uom, "MB", "uom okay"); | ||
| 318 | is( $p[1]->threshold->warning->end, 16388, "warn okay"); | ||
| 319 | is( $p[1]->threshold->critical->end, 18436, "crit okay"); | ||
| 320 | is( $p[1]->min, 1, "min ok"); | ||
| 321 | is( $p[1]->max, 2048, "max ok"); | ||
| 322 | |||
| 323 | |||
| 324 | # Mix labels with and without quotes | ||
| 325 | @p = Monitoring::Plugin::Performance->parse_perfstring(" short=4 'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 end=5 "); | ||
| 326 | is( $p[0]->label, "short" ); | ||
| 327 | is( $p[0]->rrdlabel, "short"); | ||
| 328 | is( $p[0]->value, 4, "value okay"); | ||
| 329 | is( $p[0]->uom, "", "uom okay"); | ||
| 330 | isnt( $p[0]->threshold->warning->is_set, "warn okay"); | ||
| 331 | isnt( $p[0]->threshold->critical->is_set, "crit okay"); | ||
| 332 | is( $p[0]->min, undef, "min ok"); | ||
| 333 | is( $p[0]->max, undef, "max ok"); | ||
| 334 | |||
| 335 | is( $p[1]->label, "C:\ Label: Serial Number bc22aa2e", "label okay"); | ||
| 336 | is( $p[1]->rrdlabel, "C__Label___Serial_N", "rrd label okay"); | ||
| 337 | is( $p[1]->value, 8015, "value okay"); | ||
| 338 | is( $p[1]->uom, "MB", "uom okay"); | ||
| 339 | is( $p[1]->threshold->warning->end, 16387, "warn okay"); | ||
| 340 | is( $p[1]->threshold->critical->end, 18435, "crit okay"); | ||
| 341 | is( $p[1]->min, 0, "min ok"); | ||
| 342 | is( $p[1]->max, 20484, "max ok"); | ||
| 343 | |||
| 344 | is( $p[2]->label, "end" ); | ||
| 345 | is( $p[2]->rrdlabel, "end" ); | ||
| 346 | is( $p[2]->value, 5, "value okay"); | ||
| 347 | is( $p[2]->uom, "", "uom okay"); | ||
| 348 | isnt( $p[2]->threshold->warning->is_set, "warn okay"); | ||
| 349 | isnt( $p[2]->threshold->critical->is_set, 18436, "crit okay"); | ||
| 350 | is( $p[2]->min, undef, "min ok"); | ||
| 351 | is( $p[2]->max, undef, "max ok"); | ||
| 352 | |||
| 353 | |||
| 354 | @p = Monitoring::Plugin::Performance->parse_perfstring("processes=9;WKFLSV32.exe;9="); | ||
| 355 | is_deeply( \@p, [], "Fails parsing correctly"); | ||
| 356 | |||
| 357 | # add_perfdata tests in t/Monitoring-Plugin-01.t | ||
