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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
--- check_nt.c.original 2005-03-05 04:45:05.000000000 -0500
+++ check_nt.c 2005-04-23 08:35:43.000000000 -0400
@@ -282,111 +282,74 @@
break;
case CHECK_COUNTER:
-
-
- /*
- CHECK_COUNTER has been modified to provide extensive perfdata information.
- In order to do this, some modifications have been done to the code
- and some constraints have been introduced.
-
- 1) For the sake of simplicity of the code, perfdata information will only be
- provided when the "description" field is added.
-
- 2) If the counter you're going to measure is percent-based, the code will detect
- the percent sign in its name and will attribute minimum (0%) and maximum (100%)
- values automagically, as well the ¨%" sign to graph units.
-
- 3) OTOH, if the counter is "absolute", you'll have to provide the following
- the counter unit - that is, the dimensions of the counter you're getting. Examples:
- pages/s, packets transferred, etc.
-
- 4) If you want, you may provide the minimum and maximum values to expect. They aren't mandatory,
- but once specified they MUST have the same order of magnitude and units of -w and -c; otherwise.
- strange things will happen when you make graphs of your data.
- */
-
- if (value_list == NULL)
- output_message = strdup (_("No counter specified"));
- else
- {
- preparelist (value_list); /* replace , between services with & to send the request */
- isPercent = (strchr (value_list, '%') != NULL);
-
- strtok (value_list, "&"); /* burn the first parameters */
- description = strtok (NULL, "&");
- counter_unit = strtok (NULL, "&");
- asprintf (&send_buffer, "%s&8&%s", req_password, value_list);
- fetch_data (server_address, server_port, send_buffer);
- counter_value = atof (recv_buffer);
-
-
- if (description == NULL)
- asprintf (&output_message, "%.f", counter_value);
- else if (isPercent)
- {
- counter_unit = strdup ("%");
- allRight = TRUE;
- }
-
- if ((counter_unit != NULL) && (!allRight))
- {
- minval = strtok (NULL, "&");
- maxval = strtok (NULL, "&");
-
- /* All parameters specified. Let's check the numbers */
-
- fminval = (minval != NULL) ? strtod (minval, &errcvt) : -1;
- fmaxval = (minval != NULL) ? strtod (maxval, &errcvt) : -1;
-
- if ((fminval == 0) && (minval == errcvt))
- output_message = strdup (_("Minimum value contains non-numbers"));
- else
- {
- if ((fmaxval == 0) && (maxval == errcvt))
- output_message = strdup (_("Maximum value contains non-numbers"));
- else
- allRight = TRUE; /* Everything is OK. */
-
- }
- }
- else if ((counter_unit == NULL) && (description != NULL))
- output_message = strdup (_("No unit counter specified"));
-
- if (allRight)
- {
- /* Let's format the output string, finally... */
- if (strstr(description, "%") == NULL) {
- asprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit);
- } else {
- /* has formatting, will segv if wrong */
- asprintf (&output_message, description, counter_value);
- }
- asprintf (&output_message, "%s |", output_message);
- asprintf (&output_message,"%s %s", output_message,
- fperfdata (description, counter_value,
- counter_unit, 1, warning_value, 1, critical_value,
- (!(isPercent) && (minval != NULL)), fminval,
- (!(isPercent) && (minval != NULL)), fmaxval));
- }
- }
-
- if (critical_value > warning_value)
- { /* Normal thresholds */
- if (check_critical_value == TRUE && counter_value >= critical_value)
- return_code = STATE_CRITICAL;
- else if (check_warning_value == TRUE && counter_value >= warning_value)
- return_code = STATE_WARNING;
- else
- return_code = STATE_OK;
- }
- else
- { /* inverse thresholds */
- return_code = STATE_OK;
- if (check_critical_value == TRUE && counter_value <= critical_value)
- return_code = STATE_CRITICAL;
- else if (check_warning_value == TRUE && counter_value <= warning_value)
- return_code = STATE_WARNING;
- }
+ /*
+ * Check_Counter has been rewriten for NC_Net now it processes the pref data in
+ * a more consistent way to the Nagios plug-in development guidelines.
+ * 1) if no Units of mesurement use a 0 (zero) for the UOM in the check
+ * and the units will be omited from the output.
+ * 2) it will do MIN without a MAX
+ * 3) still processes custom min and max even if it is %
+ * 4) % has a default of min 0, max 100
+ * 5) -w and -c are no longer causing a seg fault. old code said to always
+ * process both for perf data, but it should have checked that they were in use.
+ * 6) the description is only a label for perf data not a formatter...
+ ****************************************************************************/
+ if (value_list == NULL)
+ output_message = strdup (_("No counter specified"));
+ else {
+ preparelist (value_list); /* replace , between services with & to send the request */
+
+ temp_string = strtok (value_list, "&");
+ isPercent = (strchr (temp_string, '%') != NULL);
+ description = strtok (NULL, "&");
+ counter_unit = strtok (NULL, "&");
+ asprintf (&send_buffer, "%s&8&%s", req_password, value_list);
+ fetch_data (server_address, server_port, send_buffer);
+ counter_value = atof (recv_buffer);
+ if (isPercent) counter_unit = strdup ("%");
+ if ( description != NULL && counter_unit == NULL )
+ counter_unit = strdup ( "0" );
+ if ( counter_unit != NULL && description != NULL)
+ {
+ if ( counter_unit[0] == '0' ) counter_unit[0] = '\0';
+ minval = strtok (NULL, "&");
+ maxval = strtok (NULL, "&");
+ if ( minval == NULL && isPercent ) asprintf(&minval,"0");
+ if ( minval != NULL ) fminval = strtod ( minval, NULL ) ;
+ if ( maxval == NULL && isPercent ) asprintf(&maxval,"100");
+ if ( maxval != NULL ) fmaxval = strtod (maxval, NULL);
+ allRight = TRUE;
+ /* Let's format the output string, finally... */
+ asprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit);
+ asprintf (&output_message,"%s | %s", output_message,
+ fperfdata (description, counter_value,
+ counter_unit, check_warning_value, warning_value,
+ check_critical_value, critical_value,
+ (minval != NULL), fminval,
+ (maxval != NULL), fmaxval ));
+ }
+ else if (isPercent)
+ asprintf(&output_message, "%s = %.2f %%",temp_string,counter_value);
+ else
+ asprintf(&output_message, "%s = %.2f",temp_string,counter_value);
+ }
+ if (critical_value > warning_value)
+ { /* Normal thresholds */
+ if (check_critical_value == TRUE && counter_value >= critical_value)
+ return_code = STATE_CRITICAL;
+ else if (check_warning_value == TRUE && counter_value >= warning_value)
+ return_code = STATE_WARNING;
+ else
+ return_code = STATE_OK;
+ }
+ else
+ { /* inverse thresholds */
+ return_code = STATE_OK;
+ if (check_critical_value == TRUE && counter_value <= critical_value)
+ return_code = STATE_CRITICAL;
+ else if (check_warning_value == TRUE && counter_value <= warning_value)
+ return_code = STATE_WARNING;
+ }
break;
case CHECK_FILEAGE:
@@ -394,7 +357,7 @@
if (value_list==NULL)
output_message = strdup (_("No counter specified"));
else {
- preparelist(value_list); /* replace , between services with & to send the request */
+ preparelist(value_list); /* replace , between services with & to send the request */
asprintf(&send_buffer,"%s&9&%s", req_password,value_list);
fetch_data (server_address, server_port, send_buffer);
age_in_minutes = atoi(strtok(recv_buffer,"&"));
@@ -672,13 +635,32 @@
printf (_("\
COUNTER = Check any performance counter of Windows NT/2000.\n\
Request a -l parameters with the following syntax:\n\
- -l \"\\\\<performance object>\\\\counter\",\"<description>\n\
- The <description> parameter is optional and \n\
- is given to a printf output command which requires a float parameter.\n\
- If <description> does not include \"%%\", it is used as a label.\n\
+ -l \"\\\\<performance object>\\\\counter\"[,\"<Label>\"][,<UOM>][,<MIN>][,<MAX>]\n\
+ The <label> parameter is optional and is used for performance data\n\
+ If <performance object> includes \"%%\", it automaticlly considers %% performanc data.\n\
+ label is the label for performance data\n\
+ If the label is omited then the performance counter object will be used.\n\
+ UOM - Unit of Measurment -if no UOM use a zero 0, \n\
+ a zero tells check_nt to ignore the UOM in the output.\n\
+ examples of UOM- s,us,ms,%%,B,KB,MB,TB,c \n\
+ c- is for continous counter. \n\
+ Min and Max are optional but are used by third party program (RRD) for graphing.\n\
Some examples:\n\
- \"Paging file usage is %%.2f %%%%\"\n\
- \"%%.f %%%% paging file used.\"\n"));
+ -l \"\\Process(_Total)\\Thread Count\",\"Thread Count\",MB,0,1000 -w 5 -c 700\n\
+ Thread Count = 534.00 MB | 'Thread Count'=534.000000MB;5.000000;700.000000;0.000000;1000.000000\n\
+ -l \"\\Paging File(_Total)\\%% Usage\"\n\
+ \\Paging File(_Total)\\%% Usage = 36.61 %%\n\
+ -l \"\\paging file(_total)\\%% usage\"\n\
+ \\paging File(_total)\\%% usage = 36.61 %%\n\
+ -l \"\\paging file(_total)\\%% usage\",\"test1\"\n\
+ test1 = 36.60 % | test1=36.599730%;;;0.000000;100.000000\n\
+ -l \"\\paging file(_total)\\%% usage\",\"test1\",%%,20\n\
+ test1 = 36.60 % | test1=36.599730%;;;20.000000;100.000000\n\
+ -l \"\\Server\\Server Sessions\",\"test SS\",%%\n\
+ test SS = 1.00 %% | 'test SS'=1.000000%%;;;\n\
+ -l \"\\Server\\Server Sessions\",\"Server Sessions\",0,0,50 -w 20 -c 45\n\
+ Server Sessions = 1.00 c | 'Server Sessions'=1.000000;20.000000;45.000000;0.000000;50.000000\n"));
+
printf (_("Notes:\n\
- The NSClient service should be running on the server to get any information\n\
(http://nsclient.ready2run.nl).\n\
|