Changeset 75d5e70 in nscp
- Timestamp:
- 08/15/05 18:48:14 (8 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 89f1a84
- Parents:
- e26cfe0
- Files:
-
- 25 edited
-
NSCPlugin.cpp (modified) (1 diff)
-
NSClient++.cpp (modified) (2 diffs)
-
NSClient++.vcproj (modified) (3 diffs)
-
changelog (modified) (1 diff)
-
docs/CheckDisk/index.html (modified) (5 diffs)
-
docs/CheckEventLog/index.html (modified) (9 diffs)
-
docs/CheckSystem/index.html (modified) (5 diffs)
-
docs/welcome.html (modified) (2 diffs)
-
include/NSCAPI.h (modified) (2 diffs)
-
include/PDHCounter.h (modified) (3 diffs)
-
include/ServiceCmd.cpp (modified) (2 diffs)
-
include/ServiceCmd.h (modified) (1 diff)
-
include/checkHelpers.hpp (modified) (19 diffs)
-
include/config.h (modified) (2 diffs)
-
include/strEx.h (modified) (2 diffs)
-
include/thread.h (modified) (9 diffs)
-
include/utils.h (modified) (2 diffs)
-
modules/CheckDisk/CheckDisk.cpp (modified) (6 diffs)
-
modules/CheckDisk/CheckDisk.vcproj (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (4 diffs)
-
modules/CheckEventLog/CheckEventLog.h (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.cpp (modified) (22 diffs)
-
modules/CheckSystem/PDHCollector.cpp (modified) (3 diffs)
-
modules/SysTray/TrayIcon.cpp (modified) (1 diff)
-
modules/SysTray/TrayIcon.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
NSCPlugin.cpp
re26cfe0 r75d5e70 121 121 if (!fGetVersion) 122 122 throw NSPluginException(file_, "Critical error (fGetVersion)"); 123 return fGetVersion(major, minor, revision) ;123 return fGetVersion(major, minor, revision)?true:false; 124 124 } 125 125 /** -
NSClient++.cpp
re26cfe0 r75d5e70 44 44 try { 45 45 serviceControll::Install(SZSERVICENAME, SZSERVICEDISPLAYNAME, SZDEPENDENCIES); 46 serviceControll::SetDescription(SZSERVICENAME, SZSERVICEDESCRIPTION); 46 47 } catch (const serviceControll::SCException& e) { 47 48 LOG_MESSAGE_STD("Service installation failed: " + e.error_); … … 85 86 86 87 } else if ( _stricmp( "listpdh", argv[1]+1 ) == 0 ) { 87 PDH::Enumerations::str_lst lst = PDH::Enumerations::EnumObjects(); 88 for (PDH::Enumerations::str_lst::iterator it = lst.begin();it!=lst.end();++it) { 89 PDH::Enumerations::str_lst lst = PDH::Enumerations::EnumObjectItems(*it); 90 for (PDH::Enumerations::str_lst::iterator it2 = lst.begin();it2!=lst.end();++it2) { 91 std::cout << "\\" << *it <<"\\" << *it2 << std::endl;; 88 PDH::Enumerations::Objects lst = PDH::Enumerations::EnumObjects(); 89 for (PDH::Enumerations::Objects::iterator it = lst.begin();it!=lst.end();++it) { 90 if ((*it).instances.size() > 0) { 91 for (PDH::Enumerations::Instances::const_iterator it2 = (*it).instances.begin();it2!=(*it).instances.end();++it2) { 92 for (PDH::Enumerations::Counters::const_iterator it3 = (*it).counters.begin();it3!=(*it).counters.end();++it3) { 93 std::cout << "\\" << (*it).name << "(" << (*it2).name << ")\\" << (*it3).name << std::endl;; 94 } 95 } 96 } else { 97 for (PDH::Enumerations::Counters::const_iterator it2 = (*it).counters.begin();it2!=(*it).counters.end();++it2) { 98 std::cout << "\\" << (*it).name << "\\" << (*it2).name << std::endl;; 99 } 92 100 } 93 101 } -
NSClient++.vcproj
re26cfe0 r75d5e70 333 333 </File> 334 334 <File 335 RelativePath=".\include\PDHCounter.h"> 336 </File> 337 <File 335 338 RelativePath=".\Settings.h"> 336 339 </File> … … 439 442 </File> 440 443 <File 444 RelativePath=".\NSC.dist"> 445 <FileConfiguration 446 Name="Distribution|Win32"> 447 <Tool 448 Name="VCCustomBuildTool" 449 CommandLine="echo Copying $(InputFileName)... 450 cmd /c "copy $(InputDir)\$(InputFileName) $(InputDir)\Dist\$(InputName).ini" 451 " 452 Outputs="$(InputDir)\Dist\$(InputName).ini"/> 453 </FileConfiguration> 454 </File> 455 <File 441 456 RelativePath=".\NSC.ini"> 442 457 <FileConfiguration … … 460 475 </FileConfiguration> 461 476 <FileConfiguration 462 Name="Distribution|Win32"> 477 Name="Distribution|Win32" 478 ExcludedFromBuild="TRUE"> 463 479 <Tool 464 480 Name="VCCustomBuildTool" -
changelog
re26cfe0 r75d5e70 1 2005-07-31 MickeM 2 + /install now sets the serive to autostart 3 * Did some cleanup of minor code sctions 4 * (done before but not repported i think) /listpdh option added to list all pdh counters (nsclient++ /listpdh) 5 + Added service description 6 * Eventlog reworked (again) this time I hope it is better (and even usefull, but syntax has changed) 7 8 2005-07-26 MickeM 9 + Added support for ShowAll=long (to show long and short info, only applies to some areas, but avalible everywhere) 10 + Extended Drive and memory check syntax to facilitate both Free and Used space checks: MaxWarnFree / MaxWarnUsed etc) 11 12 2005-07-19 MickeM 13 * Changed thread API to use _creatthreadex as opposed to _creatthread (works better now!) 14 * Fixed UNKNOWN return code (was 4 should have been 3) 15 16 2005-07-16 MickeM 17 * Fixed drivechecks from NSClient 18 1 19 2005-07-11 MickeM 2 20 * *ALOT* of bugfixes and enhancements all checking code has been centralzed and rewritten also my nternal check scripts -
docs/CheckDisk/index.html
r6654022 r75d5e70 156 156 <th valign="top">Option </th> 157 157 <th valign="top">Values </th> 158 <th valign="top" >Description </td>158 <th valign="top" width="690">Description </td> 159 159 </th> 160 160 </tr> 161 161 <tr> 162 <td valign="top">MaxWarn <</td>162 <td valign="top">MaxWarnFree</td> 163 163 <td valign="top">Size with optional postfix (g, m, k, b, %)</td> 164 <td valign="top">The maximum size the directory is allowed before a 165 warning state is returned.</td> 166 </tr> 167 <tr> 168 <td valign="top">MaxCrit </td> 169 <td valign="top">Size with optional postfix (g, m, k, b, %) </td> 170 <td valign="top">The maximum size the directory is allowed before a 171 critical state is returned. </td> 172 </tr> 173 <tr> 174 <td valign="top">MinWarn </td> 175 <td valign="top">Size with optional postfix (g, m, k, b, %) </td> 176 <td valign="top">The minimum size the directory is allowed before a 177 warning state is returned. </td> 178 </tr> 179 <tr> 180 <td valign="top">MinCrit </td> 181 <td valign="top">Size with optional postfix (g, m, k, b, %) </td> 182 <td valign="top">The minimum size the directory is allowed before a 183 critical state is returned. </td> 164 <td valign="top" width="690">The maximum allowed free space for the 165 drive(s).</td> 166 </tr> 167 <tr> 168 <td valign="top">MaxCritFree</td> 169 <td valign="top">Size with optional postfix (g, m, k, b, %) </td> 170 <td valign="top" width="690">The maximum allowed free space for the 171 drive(s).</td> 172 </tr> 173 <tr> 174 <td valign="top">MinWarnFree</td> 175 <td valign="top">Size with optional postfix (g, m, k, b, %) </td> 176 <td valign="top" width="690">The minimum allowed free space for the 177 drive(s).</td> 178 </tr> 179 <tr> 180 <td valign="top">MinCritFree</td> 181 <td valign="top">Size with optional postfix (g, m, k, b, %) </td> 182 <td valign="top" width="690">The minimum allowed free space for the 183 drive(s).</td> 184 </tr> 185 <tr> 186 <td valign="top">MaxWarnUsed</td> 187 <td valign="top">Size with optional postfix (g, m, k, b, %)</td> 188 <td valign="top" width="690">The maximum allowed used space for the 189 drive(s).</td> 190 </tr> 191 <tr> 192 <td valign="top">MaxCritUsed</td> 193 <td valign="top">Size with optional postfix (g, m, k, b, %) </td> 194 <td valign="top" width="690">The maximum allowed used space for the 195 drive(s).</td> 196 </tr> 197 <tr> 198 <td valign="top">MinWarnUsed</td> 199 <td valign="top">Size with optional postfix (g, m, k, b, %) </td> 200 <td valign="top" width="690">The minimum allowed used space for the 201 drive(s).</td> 202 </tr> 203 <tr> 204 <td valign="top">MinCritUsed</td> 205 <td valign="top">Size with optional postfix (g, m, k, b, %) </td> 206 <td valign="top" width="690">The minimum allowed used space for the 207 drive(s).</td> 184 208 </tr> 185 209 <tr> 186 210 <td valign="top">ShowAll </td> 187 <td valign="top"><i>None</i> </td> 188 <td valign="top"> 189 <p>A Boolean flag to show size of directories that are not in an alarm 190 state. If this is not specified only drives with an alarm state will 191 be listed in the resulting string.</p> 211 <td valign="top">Emtpy, long</td> 212 <td valign="top" width="690"> 213 <p>If present will display information even if an item is not 214 reporting a state. If set to long will display more information.</p> 192 215 </td> 193 216 </tr> … … 195 218 <td valign="top">Drive </td> 196 219 <td valign="top">A Drive letter or the path of a mounted Volume </td> 197 <td valign="top">The letter of the drive to check. Notice that the drive 198 has to be a fixed drive. </td> 220 <td valign="top" width="690">The letter of the drive to check.</td> 199 221 </tr> 200 222 <tr> 201 223 <td valign="top">FilterType</td> 202 <td valign="top">FIXED, CDROM, REMOVABLE </td>203 <td valign="top" >Filter for drive type to prevent checking drives of224 <td valign="top">FIXED, CDROM, REMOVABLE, REMOTE</td> 225 <td valign="top" width="690">Filter for drive type to prevent checking drives of 204 226 certain kinds (most useful when using CheckAll). The default is FIXED</td> 205 227 </tr> … … 207 229 <td valign="top">CheckAll</td> 208 230 <td valign="top"><i>None</i></td> 209 <td valign="top" >Check all available drives</td>231 <td valign="top" width="690">Check all available drives</td> 210 232 </tr> 211 233 </table> … … 217 239 <ul> 218 240 <li> 219 <p><b>Check the size of C:\ and make sure it has 50% free space:</b></p>220 <p><code>CheckDriveSize ShowAll M axWarn=50% MaxCrit=75% Drive=c:\</code></p>221 <p><code> OK: c:: 63G (68374007808B)|c:=85% 50;75;</code></p>241 <p><b>Check the size of C:\ and make sure it has 10% free space:</b></p> 242 <p><code>CheckDriveSize ShowAll MinWarnFree=10% MinCritFree=5% Drive=c:\</code></p> 243 <p><code>CRITICAL: C:: Total: 74.5G - Used: 71.2G (95%) - Free: 3.28G (5%) < critical|C:;5%;10;5;</code></p> 222 244 <div class="config"> 223 245 <p>define command { </p> … … 241 263 <li> 242 264 <p><b>To check the size of all fixed and network drives and make sure they 243 are at least 50% full</b></p>265 have atleast 1gig free space</b></p> 244 266 <p><code>CheckDriveSize -a MinWarn=50% MinCrit=25% CheckAll FilterType=FIXED 245 267 FilterType=REMOTE</code></p> 246 <p><code> WARNING: X:\: 28% < warning|C:\=84% 50%;25%; X:\=28% 50%;25%;247 Y:\=98% 50%;25%;</code></p>268 <p><code>CRITICAL: D:\: Total: 186G - Used: 186G (99%) - Free: 709M (1%) < warning, Y:\: Total: 279G - Used: 279G (99%) - Free: 384M (1%) < critical|C:\;76514398208;1073741824;536870912; D:\;199303897088;1073741824;536870912; X:\;35467034624;1073741824;536870912; Y:\;299649466368;1073741824;536870912; 269 </code></p> 248 270 <div class="config"> 249 271 <p>define command { </p> 250 272 <p> command_name CheckAllDrives </p> 251 273 <p> command_line check_nrpe -H $HOSTADDRESS$ -p 252 5666 -c CheckDriveSize -a Drive=$ARG1$CheckAll FilterType=FIXED274 5666 -c CheckDriveSize -a CheckAll FilterType=FIXED 253 275 FilterType=REMOTE MinWarn=$ARG1$ MinCrit=$ARG2$ </p> 254 276 <p>}</p> -
docs/CheckEventLog/index.html
re26cfe0 r75d5e70 41 41 <tr> 42 42 <td valign="top">filter</td> 43 <td valign="top">in, out</td> 44 <td valign="top">Specify if you want to filter out or in records.</td> 43 <td valign="top">in, out, any, all</td> 44 <td valign="top">Specify the way you want to filter things.<p><b>in</b> 45 means any thing matching this filter will be included in the result.</p> 46 <p><b>out</b> means any thing matching this filter will be excluded 47 from the result.</p> 48 <p><b>any</b> means any of the filter rules has to match.</p> 49 <p><b>all</b> means all of the filter rules have to match.</p> 50 <p>Thus filter=all filter=in and filter=any filter=out is the 51 combinations that makes the most sence depending on your filter 52 concept.</td> 45 53 </tr> 46 54 <tr> … … 48 56 <td valign="top"><i>None</i></td> 49 57 <td valign="top">Flag to specify if you want to include string 50 representation of the error messages.</td>58 representation of the error messages.</td> 51 59 </tr> 52 60 <tr> 53 61 <td valign="top">truncate</td> 54 62 <td valign="top">length of the returned set</td> 55 <td valign="top">This wil ltruncate the output after the specified63 <td valign="top">This will truncate the output after the specified 56 64 length. As NRPE can only handle 1024 chars you need to truncate the 57 65 output.</td> 58 66 </tr> 59 67 <tr> 60 <td valign="top"> warning-count</td>68 <td valign="top">MaxWarn</td> 61 69 <td valign="top">number of records</td> 62 70 <td valign="top">The maximum records to allow before reporting a … … 64 72 </tr> 65 73 <tr> 66 <td valign="top"> critical-count</td>74 <td valign="top">MaxCrit</td> 67 75 <td valign="top">number of records</td> 68 76 <td valign="top">The maximum records to allow before reporting a … … 82 90 filter-eventSource</td> 83 91 <td valign="top"> 84 regexp</td>92 string expression</td> 85 93 <td valign="top"> 86 The name of the source of the event.</td> 94 The name of the source of the event. Can be a substring or 95 regularexpression</td> 87 96 </tr> 88 97 <tr> … … 90 99 filter-generated</td> 91 100 <td valign="top"> 92 Time with optional postfix</td>101 time expression</td> 93 102 <td valign="top"> 94 103 Time ago the message was generated</td> … … 98 107 filter-written</td> 99 108 <td valign="top"> 100 Time with optional postfix</td>109 time expression</td> 101 110 <td valign="top"> 102 111 Time ago the message was written to the log</td> … … 106 115 filter-message</td> 107 116 <td valign="top"> 108 regexp</td>117 string expression</td> 109 118 <td valign="top"> 110 Filter strings in the message.</td> 119 Filter strings in the message. Can be a substring or 120 regularexpression</td> 111 121 </tr> 112 122 </table> 113 <p>The Time with optional postfix is a way to simply specify large times by 114 adding unit postfix. The available postfixes are S for Second, M for Minute, 115 H for Hour, D for Day and W for week. </p> 123 <p> </p> 124 <p>A time expression is a date/time intervall as a number prefixed by a 125 filter prefix (<, >, =, !=) and followed by a unit postfix (m, s, h, d, w). 126 A few examples of time expression are: filter-generated=>2d means filter 127 will match any records older than 2 days, filter-generated=<2h means match 128 any records newver then 2 hours.</p> 129 <p>A string expression is a key followed by a string that specifies a string 130 expression. Currently substr and regexp are supported. Thus you enter 131 filter-message=regexp:(foo|bar) to enter a regular expression and 132 filter-message=substr:foo to enter a substring patter match.</p> 116 133 <h3>Examples</h3> 117 134 <div class="example"> … … 122 139 all warnings. Allow 3 errors before a warning is issued and 7 before 123 140 a critical state.</b></p> 124 <p><code>checkEventLog file=system file=application filter-eventType=warning filter-generated=1d filter-eventSource=Cdrom filter-eventSource=NSClient warning-count=3 critical-count=7</code></p> 141 <p><code>checkEventLog file=system file=application 142 MaxWarn=1 MaxCrit=1 filter-generated=>2d filter-eventSource=substr:Service 143 filter-eventSource=substr:Tcpip filter=out filter=any</code></p> 125 144 <p><code>CRITICAL: 27 > critical: ESENT, ESENT, ESENT, ESENT,...</code></p> 126 145 <div class="config"> … … 128 147 <p> command_name check_event_log </p> 129 148 <p> command_line check_nrpe -H $HOSTADDRESS$ -p 130 5666 -c checkEventLog -a file=system file=application filter-eventType=warning filter-generated=1d filter-eventSource=Cdrom filter-eventSource=NSClient warning-count=3 critical-count=7 </p> 149 5666 -c checkEventLog -a file=system file=application MaxWarn=1 MaxCrit=1 150 filter-generated=>2d filter-eventSource=substr:Service 151 filter-eventSource=substr:Tcpip filter=out filter=any</p> 131 152 <p>}</p> 132 153 <p> check_command check_event_log -
docs/CheckSystem/index.html
re26cfe0 r75d5e70 152 152 </tr> 153 153 <tr> 154 <td valign="top">warn</td> 155 <td valign="top">time</td> 156 <td valign="top">Minimum uptime time to not generate a warning state.</td> 157 </tr> 158 <tr> 159 <td valign="top">crit</td> 160 <td valign="top">time</td> 161 <td valign="top">Minimum uptime time to not generate a critical state.</td> 154 <td valign="top">MaxCrit</td> 155 <td valign="top">time</td> 156 <td valign="top">Maximum time the system is allowed to be up</td> 157 </tr> 158 <tr> 159 <td valign="top">MinCrit</td> 160 <td valign="top">time</td> 161 <td valign="top">Minimum time the system is allowed to be up</td> 162 </tr> 163 <tr> 164 <td valign="top">MaxWarn</td> 165 <td valign="top">time</td> 166 <td valign="top">Maximum time the system is allowed to be up</td> 167 </tr> 168 <tr> 169 <td valign="top">MinWarn</td> 170 <td valign="top">time</td> 171 <td valign="top">Minimum time the system is allowed to be up</td> 162 172 </tr> 163 173 <tr> … … 173 183 <li> 174 184 <p>Check that the system has been running for at least a day:</p> 175 <p><code>checkUpTime warn=1d crit=12h</code></p>185 <p><code>checkUpTime MinWarn=1d MinWarn=12h</code></p> 176 186 <p><code>Client has uptime (19h) < warning (24h)</code></p> 177 187 </li> … … 316 326 can be check as there are a lot of performance counter. To find performance 317 327 counters use the program perfmon that is shipped with windows. An important 318 note is that performance counters are language and version specific.</p> 319 <p><i><b>This is currently broken and will be fixed in the next version.</b></i></p> 328 note is that performance counters are language and version specific. You can 329 list all avalible performance counters using the /listpdh command line 330 option.</p> 320 331 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" id="table16"> 321 332 <tr> … … 326 337 <tr> 327 338 <td valign="top">MaxWarn</td> 328 <td valign="top">Size GMKB%</td> 329 <td valign="top">The maximum size allowed before a warning state is 330 returned.</td> 339 <td valign="top">Number</td> 340 <td valign="top">Maximum allowed number</td> 331 341 </tr> 332 342 <tr> 333 343 <td valign="top">MaxCrit</td> 334 <td valign="top">Size GMKB%</td> 335 <td valign="top">The maximum size allowed before a critical state is 336 returned.</td> 344 <td valign="top">Number</td> 345 <td valign="top">Maximum allowed number</td> 337 346 </tr> 338 347 <tr> 339 348 <td valign="top">MinWarn</td> 340 <td valign="top">Size GMKB%</td> 341 <td valign="top">The minimum size allowed before a warning state is 342 returned.</td> 349 <td valign="top">Number</td> 350 <td valign="top">Minimum allowed number</td> 343 351 </tr> 344 352 <tr> 345 353 <td valign="top">MinCrit</td> 346 <td valign="top">Size GMKB%</td> 347 <td valign="top">The minimum size allowed before a critical state is 348 returned.</td> 354 <td valign="top">Number</td> 355 <td valign="top">Minimumallowed number</td> 349 356 </tr> 350 357 <tr> 351 358 <td valign="top">ShowAll</td> 352 359 <td valign="top"><i>None</i></td> 353 <td valign="top">A Boolean flag to show size even if no state is returned 354 (?).</td> 360 <td valign="top">A Boolean flag to show value even if no state is returned.</td> 355 361 </tr> 356 362 <tr> … … 372 378 <p>Check that mutex count (on WinXP) is below 500:</p> 373 379 <p><code>checkCounter "Counter:mutex=\\Objects\\Mutexes" ShowAll MaxWarn=500 MaxCrit=1000</code></p> 374 <p><code>WARNING: mutex: 673 > warning| page=673;500;1000;</code></p>380 <p><code>WARNING: mutex: 673 > warning|mutex=673;500;1000;</code></p> 375 381 </li> 376 382 </ul> -
docs/welcome.html
re26cfe0 r75d5e70 33 33 <table id="table17" border="0" cellspacing="0" cellpadding="0" class="MsoNormalTable"> 34 34 <tr> 35 <td valign="top">2005-06-09</td> 36 <td>Update with a lot of nice things that will simplify 37 configuration (I hope).<p>Enhances/Fixes:</p> 38 <ul> 39 <li>Autodecteds windows version and language. Hopefully this 40 will reduce configuration problems.</li> 41 <li>Fixed " escapes in nsc.ini (NRPE Copmmands section)</li> 42 </ul> 43 <p>Added:</p> 44 <ul> 45 <li>A decent CheckEventLog (it can now be used, and I think as 46 soon as I have time to update the docs a bit more might be a 47 nice and usable addition.</li> 48 </ul> 49 </td> 50 </tr> 51 <tr> 52 <td valign="top">2005-05-29</td> 53 <td>Minor update that fixes a few bugs.<p>Enhances/Fixes:</p> 54 <ul> 55 <li>Fixed PROCSTATE and SERVICESTATE return state.</li> 56 <li>Fixed performance data for drives (and possibly other places)</li> 57 </ul> 58 <p>Added:</p> 59 <ul> 60 <li>Added support for individual size in CheckDriveSize and CheckFileSize 61 (size has to be specified before a drive/path).</li> 62 </ul> 35 <td valign="top">2005-07-31</td> 36 <td>Mainly fixes some minor issues, also adds support for FreeSpace 37 checks (in addition to UsedSpace check) as well as "long description 38 support" and a reworked EventLog checker.<br> 39 <br> 40 No updated documentation yet but hopefully all outstanding issues 41 has been fixed.<br> 42 <br> 43 Extract from change log:<br> 44 + /install now sets the serivice to autostart<br> 45 + Added service description<br> 46 * added /listpdh option added to list all pdh counters<br> 47 * Eventlog reworked (again) this time I hope it is better <br> 48 + Added support for ShowAll=long (to show more information)<br> 49 + Extended Drive and memory check syntax to facilitate both Free and 50 Used space checks: MaxWarnFree / MaxWarnUsed etc)<br> 51 * Changed thread API to use _creatthreadex as opposed to _creatthread 52 (works better now!)<br> 53 * Fixed UNKNOWN return code (was 4 should have been 3)<br> 54 * Fixed drivechecks from NSClient<br> 55 </td> 56 </tr> 57 <tr> 58 <td valign="top">2005-07-12</td> 59 <td>Update with a lot bugfixes 63 60 </td> 64 61 </tr> … … 68 65 <a href="http://nscplus.sf.net" target="_top">http://nscplus.sf.net</a></p> 69 66 <p>Latest version is 70 <a href="http://prdownloads.sourceforge.net/nscplus/NSClient++-0.2. 2.zip?download">71 NSClient++ 0.2. 2.zip</a></p>67 <a href="http://prdownloads.sourceforge.net/nscplus/NSClient++-0.2.4d.zip?download"> 68 NSClient++ 0.2.4.zip</a></p> 72 69 <h1>Modules</h1> 73 70 <p>NSClient++ comes with a few modules out of the box that does various checks. -
include/NSCAPI.h
r1d9338a r75d5e70 8 8 returnOK = 0, 9 9 returnWARN = 1, 10 returnUNKNOWN = 4,10 returnUNKNOWN = 3, 11 11 returnInvalidBufferLen = -2, 12 12 returnIgnored = -1 … … 25 25 const int returnWARN = 1; 26 26 const int returnCRIT = 2; 27 const int returnUNKNOWN = 4;27 const int returnUNKNOWN = 3; 28 28 const int returnInvalidBufferLen = -2; 29 29 const int returnIgnored = -1; -
include/PDHCounter.h
re26cfe0 r75d5e70 262 262 class Enumerations { 263 263 public: 264 typedef std::list<std::string> str_lst; 265 static str_lst EnumObjects() { 264 265 struct Counter { 266 std::string name; 267 }; 268 typedef std::list<Counter> Counters; 269 struct Instance { 270 std::string name; 271 }; 272 typedef std::list<Instance> Instances; 273 struct Object { 274 std::string name; 275 Instances instances; 276 Counters counters; 277 }; 278 279 typedef std::list<Object> Objects; 280 static Objects EnumObjects(DWORD dwDetailLevel = PERF_DETAIL_WIZARD) { 281 Objects ret; 282 283 DWORD dwObjectBufLen = 0; 284 LPTSTR szObjectBuffer = NULL; 285 PDH_STATUS status = PdhEnumObjects(NULL, NULL, szObjectBuffer, &dwObjectBufLen, dwDetailLevel, FALSE); 286 if (status != PDH_MORE_DATA) 287 throw PDHException("PdhEnumObjects failed when trying to retrieve size of object buffer", status); 288 289 szObjectBuffer = new char[dwObjectBufLen+1024]; 290 status = PdhEnumObjects(NULL, NULL, szObjectBuffer, &dwObjectBufLen, dwDetailLevel, FALSE); 291 if (status != ERROR_SUCCESS) 292 throw PDHException("PdhEnumObjects failed when trying to retrieve object buffer", status); 293 294 char *cp=szObjectBuffer; 295 while(*cp != '\0') { 296 Object o; 297 o.name = cp; 298 ret.push_back(o); 299 cp += lstrlen(cp)+1; 300 } 301 delete [] szObjectBuffer; 302 303 for (Objects::iterator it = ret.begin(); it != ret.end(); ++it) { 304 DWORD dwCounterBufLen = 0; 305 LPTSTR szCounterBuffer = NULL; 306 DWORD dwInstanceBufLen = 0; 307 LPTSTR szInstanceBuffer = NULL; 308 status = PdhEnumObjectItems(NULL, NULL, (*it).name.c_str(), szCounterBuffer, &dwCounterBufLen, szInstanceBuffer, &dwInstanceBufLen, dwDetailLevel, 0); 309 if (status != PDH_MORE_DATA) 310 throw PDHException("PdhEnumObjectItems failed when trying to retrieve size for " + (*it).name, status); 311 szCounterBuffer = new char[dwCounterBufLen+1024]; 312 szInstanceBuffer = new char[dwInstanceBufLen+1024]; 313 status = PdhEnumObjectItems(NULL, NULL, (*it).name.c_str(), szCounterBuffer, &dwCounterBufLen, szInstanceBuffer, &dwInstanceBufLen, dwDetailLevel, 0); 314 if (status != ERROR_SUCCESS) 315 throw PDHException("PdhEnumObjectItems failed when trying to retrieve buffer for " + (*it).name, status); 316 317 if (dwCounterBufLen > 0) { 318 cp=szCounterBuffer; 319 while(*cp != '\0') { 320 Counter o; 321 o.name = cp; 322 (*it).counters.push_back(o); 323 cp += lstrlen(cp)+1; 324 } 325 } 326 if (dwInstanceBufLen > 0) { 327 cp=szInstanceBuffer; 328 while(*cp != '\0') { 329 Instance o; 330 o.name = cp; 331 (*it).instances.push_back(o); 332 cp += lstrlen(cp)+1; 333 } 334 } 335 delete [] szCounterBuffer; 336 delete [] szInstanceBuffer; 337 } 338 return ret; 339 } 340 /* 341 static str_lst EnumObjectItems(std::string object) { 266 342 str_lst ret; 267 343 DWORD bufLen = 4096; 344 DWORD bufLen2 = 0; 268 345 LPTSTR buf = new char[bufLen+1]; 269 PDH_STATUS status = PdhEnumObject s(NULL, NULL, buf, &bufLen, PERF_DETAIL_EXPERT, FALSE);346 PDH_STATUS status = PdhEnumObjectItems(NULL, NULL, object.c_str(), buf, &bufLen, NULL, &bufLen2, PERF_DETAIL_WIZARD, 0); 270 347 if (status == ERROR_SUCCESS) { 271 348 char *cp=buf; … … 277 354 return ret; 278 355 } 279 static str_lst EnumObjectI tems(std::string object) {356 static str_lst EnumObjectInstances(std::string object) { 280 357 str_lst ret; 281 358 DWORD bufLen = 4096; 282 359 DWORD bufLen2 = 0; 283 360 LPTSTR buf = new char[bufLen+1]; 284 PDH_STATUS status = PdhEnumObjectItems(NULL, NULL, object.c_str(), buf, &bufLen, NULL, &bufLen2, PERF_DETAIL_EXPERT, 0);361 PDH_STATUS status = PdhEnumObjectItems(NULL, NULL, object.c_str(), NULL, &bufLen2, buf, &bufLen, PERF_DETAIL_WIZARD, 0); 285 362 if (status == ERROR_SUCCESS) { 286 363 char *cp=buf; … … 292 369 return ret; 293 370 } 371 */ 294 372 static bool validate(std::string counter, std::string &error) { 295 373 PDH_STATUS status = PdhValidatePath(counter.c_str()); -
include/ServiceCmd.cpp
r1e62ed5 r75d5e70 47 47 SERVICE_ALL_ACCESS, // desired access 48 48 SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS , // service type 49 SERVICE_ DEMAND_START, // start type49 SERVICE_AUTO_START, // start type 50 50 SERVICE_ERROR_NORMAL, // error control type 51 51 szPath, // service's binary … … 187 187 CloseServiceHandle(schSCManager); 188 188 } 189 190 void SetDescription(std::string name, std::string desc) { 191 SERVICE_DESCRIPTION descr; 192 SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); 193 if (!schSCManager) 194 throw SCException("OpenSCManager failed."); 195 SC_HANDLE schService = OpenService(schSCManager, TEXT(name.c_str()), SERVICE_ALL_ACCESS); 196 if (!schService) { 197 CloseServiceHandle(schSCManager); 198 throw SCException("OpenService failed."); 199 } 200 201 LPSTR d = new char[desc.length()+1]; 202 strncpy(d, desc.c_str(), desc.length()); 203 descr.lpDescription = d; 204 BOOL bResult = ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &descr); 205 delete [] d; 206 CloseServiceHandle(schService); 207 CloseServiceHandle(schSCManager); 208 if (!bResult) 209 throw SCException("ChangeServiceConfig2 failed."); 210 } 189 211 } -
include/ServiceCmd.h
ra0528c4 r75d5e70 12 12 void Start(std::string); 13 13 void Stop(std::string); 14 void SetDescription(std::string,std::string); 14 15 } -
include/checkHelpers.hpp
re26cfe0 r75d5e70 35 35 return str + " (unknown)"; 36 36 } 37 37 std::string formatNotFound(std::string str, ResultType what) { 38 if (what == warning) 39 return str + "not found (warning)"; 40 else if (what == critical) 41 return str + "not found (critical)"; 42 return str + "not found (unknown)"; 43 } 44 45 typedef enum {showLong, showShort, showProblems, showUnknown} showType; 38 46 template <class TContents> 39 47 struct CheckConatiner { … … 43 51 std::string data; 44 52 std::string alias; 45 CheckConatiner() 53 54 showType show; 55 56 57 CheckConatiner() : show(showUnknown) 46 58 {} 47 59 CheckConatiner(std::string data_, TContents warn_, TContents crit_) 48 : data(data_), warn(warn_), crit(crit_) 60 : data(data_), warn(warn_), crit(crit_), show(showUnknown) 49 61 {} 50 62 CheckConatiner(std::string name_, std::string alias_, TContents warn_, TContents crit_) 51 : data(data_), alias(alias_), warn(warn_), crit(crit_) 63 : data(data_), alias(alias_), warn(warn_), crit(crit_), show(showUnknown) 64 {} 65 CheckConatiner(const TThisType &other) 66 : data(other.data), alias(other.alias), warn(other.warn), crit(other.crit), show(other.show) 52 67 {} 53 68 std::string getAlias() { … … 61 76 if (!crit.hasBounds()) 62 77 crit = def.crit; 63 } 64 void formatString(std::string &message, typename TContents::TValueType &value) { 65 crit.formatString(message, value); 66 message = getAlias() + ": " + message; 78 if (show == showUnknown) 79 show = def.show; 80 } 81 bool showAll() { 82 return show != showProblems; 67 83 } 68 84 std::string gatherPerfData(typename TContents::TValueType &value) { 69 85 return crit.gatherPerfData(getAlias(), value, warn, crit); 70 86 } 71 void runCheck(typename TContents::TValueType &value, NSCAPI::nagiosReturn &returnCode, std::string &message, std::string &perf , bool bShowAll) {87 void runCheck(typename TContents::TValueType &value, NSCAPI::nagiosReturn &returnCode, std::string &message, std::string &perf) { 72 88 std::string tstr; 73 89 if (crit.check(value, getAlias(), tstr, critical)) { … … 75 91 } else if (warn.check(value, getAlias(), tstr, warning)) { 76 92 NSCHelper::escalteReturnCodeToWARN(returnCode); 77 }else if (bShowAll) { 78 formatString(tstr, value); 93 }else if (show == showLong) { 94 tstr = getAlias() + ": " + TContents::toStringLong(value); 95 }else if (show == showShort) { 96 tstr = getAlias() + ": " + TContents::toStringShort(value); 79 97 } 80 98 perf += gatherPerfData(value); … … 90 108 class disk_size_handler { 91 109 public: 110 static std::string print(TType value) { 111 return strEx::itos_as_BKMG(value); 112 } 92 113 static TType parse(std::string s) { 93 114 return strEx::stoi64_as_BKMG(s); … … 96 117 return strEx::stoi64(s); 97 118 } 98 static std::string print(TType value) {99 return strEx::itos_as_BKMG(value);100 }101 119 static std::string print_percent(TType value) { 102 120 return strEx::itos(value) + "%"; … … 104 122 static std::string print_unformated(TType value) { 105 123 return strEx::itos(value); 124 } 125 126 static std::string key_total() { 127 return "Total: "; 128 } 129 static std::string key_lower() { 130 return "Used: "; 131 } 132 static std::string key_upper() { 133 return "Free: "; 106 134 } 107 135 }; … … 239 267 } 240 268 241 std::string toString(TType value) const { 269 static std::string toStringLong(TType value) { 270 return THandler::print(value); 271 } 272 static std::string toStringShort(TType value) { 242 273 return THandler::print(value); 243 274 } … … 246 277 } 247 278 248 inline bool isAbove(TType value) const {249 return check(value)==above;250 }251 inline bool isBelow(TType value) const {252 return check(value)==below;253 }254 279 const NumericBounds & operator=(std::string value) { 255 280 set(value); … … 274 299 }; 275 300 301 302 template <typename TTypeValue, typename TTypeTotal = TTypeValue> 303 struct PercentageValueType { 304 typedef TTypeValue TValueType; 305 TTypeValue value; 306 TTypeTotal total; 307 308 TTypeValue getUpperPercentage() { 309 return 100-(value*100/total); 310 } 311 TTypeValue getLowerPercentage() { 312 return (value*100)/total; 313 } 314 }; 315 276 316 template <typename TType = int, class THandler = int_handler > 277 317 class NumericPercentageBounds { 278 318 public: 279 319 typedef enum { 280 none, 281 percentage, 282 size, 320 none = 0, 321 percentage_upper = 1, 322 percentage_lower = 2, 323 value_upper = 3, 324 value_lower = 4, 283 325 } checkTypes; 284 326 327 class InternalValue { 328 NumericPercentageBounds *pParent_; 329 bool isUpper_; 330 public: 331 332 InternalValue(bool isUpper) : pParent_(NULL), isUpper_(isUpper) {} 333 void setParent(NumericPercentageBounds *pParent) { 334 pParent_ = pParent; 335 } 336 const InternalValue & operator=(std::string value) { 337 std::cout << "Setting value: " << value << std::endl; 338 std::string::size_type p = value.find_first_of('%'); 339 if (p != std::string::npos) { 340 if (isUpper_) 341 pParent_->setPercentageUpper(value); 342 else 343 pParent_->setPercentageLower(value); 344 } else { 345 if (isUpper_) 346 pParent_->setUpper(value); 347 else 348 pParent_->setLower(value); 349 } 350 return *this; 351 } 352 353 }; 354 285 355 checkTypes type_; 286 TType value_; 287 TType max_; 356 typename TType::TValueType value_; 288 357 typedef typename TType TValueType; 289 358 typedef THandler TFormatType; 290 359 typedef NumericPercentageBounds<TType, THandler> TMyType; 291 292 NumericPercentageBounds() : type_(none), value_(0), max_(0) {} 360 InternalValue upper; 361 InternalValue lower; 362 363 NumericPercentageBounds() : type_(none), upper(true), lower(false) { 364 upper.setParent(this); 365 lower.setParent(this); 366 } 293 367 294 368 NumericPercentageBounds(const NumericPercentageBounds &other) { 295 369 type_ = other.type_; 296 370 value_ = other.value_; 297 max_ = other.max_; 298 } 299 void setMax(TType max) { max_ = max; } 300 371 } 301 372 checkResultType check(TType value) const { 302 if (type_ == percentage) { 303 if (((value*100)/max_) == value_) 373 if (type_ == percentage_lower) { 374 std::cout << "Checking: percentage_lower " << value.getLowerPercentage() << " < " << value_ << std::endl; 375 if (value.getLowerPercentage() == value_) 304 376 return same; 305 else if ( ((value*100)/max_) > value_)377 else if (value.getLowerPercentage() > value_) 306 378 return above; 307 else 308 return below; 379 } else if (type_ == percentage_upper) { 380 std::cout << "Checking: percentage_upper " << value.getUpperPercentage() << " < " << value_ << std::endl; 381 if (value.getUpperPercentage() == value_) 382 return same; 383 else if (value.getUpperPercentage() > value_) 384 return above; 385 } else if (type_ == value_lower) { 386 std::cout << "Checking: value_lower " << value.total << " < " << value_ << std::endl; 387 if (value.value == value_) 388 return same; 389 else if (value.value > value_) 390 return above; 391 } else if (type_ == value_upper) { 392 std::cout << "Checking: value_upper " << (value.total-value.value) << " < " << value_ << std::endl; 393 if ((value.total-value.value) == value_) 394 return same; 395 else if ((value.total-value.value) > value_) 396 return above; 309 397 } else { 310 if (value == value_) 311 return same; 312 else if (value > value_) 313 return above; 314 return below; 315 } 316 } 317 std::string toString(TType value) const { 318 if (type_ == percentage) 319 return THandler::print_percent((value*100)/max_); 320 return THandler::print(value); 398 std::cout << "Damn...: " << type_ << std::endl; 399 throw "Damn..."; 400 } 401 return below; 402 } 403 static std::string toStringShort(TType value) { 404 return THandler::print(value.value); 405 406 } 407 static std::string toStringLong(TType value) { 408 return 409 THandler::key_total() + THandler::print(value.total) + 410 " - " + THandler::key_lower() + THandler::print(value.value) + 411 " (" + THandler::print_percent(value.getLowerPercentage()) + ")" + 412 " - " + THandler::key_upper() + THandler::print(value.total-value.value) + 413 " (" + THandler::print_percent(value.getUpperPercentage()) + ")"; 321 414 } 322 415 inline bool hasBounds() const { 323 416 return type_ != none; 324 417 } 325 inline bool isPercentage() const { 326 return type_ == percentage; 327 } 328 inline bool isAbove(TType value, TType max) const { 329 return check(value, max)==above; 330 } 331 inline bool isBelow(TType value, TType max) const { 332 return check(value, max)==below; 333 } 334 TType getPerfBound(TType value) { 418 typename TType::TValueType getPerfBound(TType value) { 335 419 return value_; 336 420 } 337 std::string gatherPerfData(std::string alias, TType &value, TType warn, TType crit) {338 if ( isPercentage()) {421 std::string gatherPerfData(std::string alias, TType &value, typename TType::TValueType warn, typename TType::TValueType crit) { 422 if (type_ == percentage_upper) { 339 423 return alias + ";" 340 + THandler::print_unformated( (value*100)/max_) + "%;"424 + THandler::print_unformated(value.getUpperPercentage()) + "%;" 341 425 + THandler::print_unformated(warn) + ";" 342 426 + THandler::print_unformated(crit) + "; "; 427 } else if (type_ == percentage_lower) { 428 return alias + ";" 429 + THandler::print_unformated(value.getLowerPercentage()) + "%;" 430 + THandler::print_unformated(warn) + ";" 431 + THandler::print_unformated(crit) + "; "; 343 432 } else { 344 433 return alias + ";" 345 + THandler::print_unformated(value) + ";" 346 + THandler::print_unformated((warn*max_)/100) + ";" 347 + THandler::print_unformated((crit*max_)/100) + "; "; 348 } 349 } 350 const NumericPercentageBounds & operator=(std::string value) { 351 set(value); 352 return *this; 434 + THandler::print_unformated(value.value) + ";" 435 + THandler::print_unformated(warn) + ";" 436 + THandler::print_unformated(crit) + "; "; 437 } 353 438 } 354 439 private: 355 void set(std::string s) { 356 std::string::size_type p = s.find_first_of('%'); 357 if (p == std::string::npos) { 358 value_ = THandler::parse(s); 359 type_ = size; 360 } else { 361 value_ = THandler::parse_percent(s); 362 type_ = percentage; 363 } 440 void setUpper(std::string s) { 441 std::cout << "Setting value:U " << s << std::endl; 442 value_ = THandler::parse(s); 443 type_ = value_upper; 444 } 445 void setLower(std::string s) { 446 std::cout << "Setting value:L " << s << std::endl; 447 value_ = THandler::parse(s); 448 type_ = value_lower; 449 } 450 void setPercentageUpper(std::string s) { 451 value_ = THandler::parse_percent(s); 452 type_ = percentage_upper; 453 } 454 void setPercentageLower(std::string s) { 455 value_ = THandler::parse_percent(s); 456 type_ = percentage_lower; 364 457 } 365 458 }; … … 379 472 return (value & value_) != 0; 380 473 } 381 std::string toString(TType value) const { 474 static std::string toStringLong(TType value) { 475 return THandler::print(value); 476 } 477 static std::string toStringShort(TType value) { 382 478 return THandler::print(value); 383 479 } … … 427 523 return state.hasBounds() || max.hasBounds() || min.hasBounds(); 428 524 } 525 526 static std::string toStringLong(typename TValueType &value) { 527 return TNumericHolder::toStringLong(value.count) + ", " + TStateHolder::toStringLong(value.state); 528 } 529 static std::string toStringShort(typename TValueType &value) { 530 return TNumericHolder::toStringShort(value.count); 531 } 532 /* 429 533 void formatString(std::string &message, typename TValueType &value) { 430 534 if (state.hasBounds()) … … 435 539 message = max.toString(value.count); 436 540 } 541 */ 437 542 std::string gatherPerfData(std::string alias, typename TValueType &value, TMyType &warn, TMyType &crit) { 438 543 if (state.hasBounds()) { … … 447 552 bool check(typename TValueType &value, std::string lable, std::string &message, ResultType type) { 448 553 if ((state.hasBounds())&&(!state.check(value.state))) { 449 message = lable + ": " + formatState( state.toString(value.state), type);554 message = lable + ": " + formatState(TStateHolder::toStringShort(value.state), type); 450 555 return true; 451 556 } else if ((max.hasBounds())&&(max.check(value.count) != below)) { 452 message = lable + ": " + formatAbove( max.toString(value.count), type);557 message = lable + ": " + formatAbove(TNumericHolder::toStringShort(value.count), type); 453 558 return true; 454 559 } else if ((min.hasBounds())&&(min.check(value.count) != above)) { 455 message = lable + ": " + formatBelow( min.toString(value.count), type);560 message = lable + ": " + formatBelow(TNumericHolder::toStringShort(value.count), type); 456 561 return true; 457 562 } else { … … 478 583 return state.hasBounds(); 479 584 } 480 void formatString(std::string &message, typename TValueType &value) { 481 message = state.toString(value); 585 static std::string toStringLong(typename TValueType &value) { 586 return TStateHolder::toStringLong(value); 587 } 588 static std::string toStringShort(typename TValueType &value) { 589 return TStateHolder::toStringShort(value); 482 590 } 483 591 std::string gatherPerfData(std::string alias, typename TValueType &value, TMyType &warn, TMyType &crit) { … … 489 597 bool check(typename TValueType &value, std::string lable, std::string &message, ResultType type) { 490 598 if ((state.hasBounds())&&(!state.check(value))) { 491 message = lable + ": " + formatState( state.toString(value), type);599 message = lable + ": " + formatState(TStateHolder::toStringLong(value), type); 492 600 return true; 493 601 } else { … … 517 625 return max.hasBounds() || min.hasBounds(); 518 626 } 519 void formatString(std::string &message, typename THolder::TValueType &value) { 520 message = max.toString(value); 627 static std::string toStringLong(typename THolder::TValueType &value) { 628 return THolder::toStringLong(value); 629 } 630 static std::string toStringShort(typename THolder::TValueType &value) { 631 return THolder::toStringShort(value); 521 632 } 522 633 std::string gatherPerfData(std::string alias, typename THolder::TValueType &value, TMyType &warn, TMyType &crit) { … … 530 641 bool check(typename THolder::TValueType &value, std::string lable, std::string &message, ResultType type) { 531 642 if ((max.hasBounds())&&(max.check(value) != below)) { 532 message = lable + ": " + formatAbove( max.toString(value), type);643 message = lable + ": " + formatAbove(THolder::toStringLong(value), type); 533 644 return true; 534 645 } else if ((min.hasBounds())&&(min.check(value) != above)) { 535 message = lable + ": " + formatBelow( min.toString(value), type);646 message = lable + ": " + formatBelow(THolder::toStringLong(value), type); 536 647 return true; 537 648 } else { … … 545 656 typedef MaxMinBounds<NumericBounds<__int64, int64_handler> > MaxMinBoundsInt64; 546 657 typedef MaxMinBounds<NumericBounds<int, int_handler> > MaxMinBoundsInteger; 658 typedef MaxMinBounds<NumericBounds<unsigned int, int_handler> > MaxMinBoundsUInteger; 547 659 typedef MaxMinBounds<NumericBounds<disk_size_type, disk_size_handler<disk_size_type> > > MaxMinBoundsDiscSize; 548 660 typedef MaxMinBounds<NumericBounds<time_type, time_handler<time_type> > > MaxMinBoundsTime; 549 661 550 662 551 typedef MaxMinBounds<NumericPercentageBounds<int, int_handler> > MaxMinPercentageBoundsInteger; 552 typedef MaxMinBounds<NumericPercentageBounds<__int64, int64_handler> > MaxMinPercentageBoundsInt64; 553 typedef MaxMinBounds<NumericPercentageBounds<double, double_handler> > MaxMinPercentageBoundsDouble; 554 typedef MaxMinBounds<NumericPercentageBounds<disk_size_type, disk_size_handler<> > > MaxMinPercentageBoundsDiskSize; 663 //typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<int ,int>, int_handler> > MaxMinPercentageBoundsInteger; 664 //typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<__int64, __int64>, int64_handler> > MaxMinPercentageBoundsInt64; 665 //typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<double, double>, double_handler> > MaxMinPercentageBoundsDouble; 666 typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<disk_size_type, disk_size_type>, disk_size_handler<> > > MaxMinPercentageBoundsDiskSize; 667 typedef MaxMinBounds<NumericPercentageBounds<PercentageValueType<__int64, __int64>, disk_size_handler<__int64> > > MaxMinPercentageBoundsDiskSizei64; 555 668 556 669 typedef MaxMinStateBounds<MaxMinStateValueType<int, state_type>, NumericBounds<int, int_handler>, StateBounds<state_type, state_handler> > MaxMinStateBoundsStateBoundsInteger; -
include/config.h
re26cfe0 r75d5e70 9 9 // internal name of the service 10 10 #define SZSERVICENAME "NSClient++" 11 12 // Description of service 13 #define SZSERVICEDESCRIPTION "Nagios Windows Agent (Provides performance data for Nagios server)" 11 14 12 15 // displayed name of the service … … 83 86 #define MAIN_SECTION_TITLE "Settings" 84 87 #define MAIN_MASTERKEY "master_key" 85 #define MAIN_MASTERKEY_DEFAULT "This is a secret key th et you should change"88 #define MAIN_MASTERKEY_DEFAULT "This is a secret key that you should change" 86 89 #define MAIN_OBFUSCATED_PASWD "obfuscated_password" 87 90 #define MAIN_OBFUSCATED_PASWD_DEFAULT "" -
include/strEx.h
re26cfe0 r75d5e70 11 11 12 12 namespace strEx { 13 14 inline void append_list(std::string &lst, std::string &append) { 15 if (!lst.empty()) 16 lst += ", "; 17 lst += append; 18 } 19 13 20 14 21 inline void replace(std::string &string, std::string replace, std::string with) { … … 81 88 return value * smallest_unit; 82 89 } 90 83 91 inline unsigned long long stoi64_as_time(std::string time, unsigned int smallest_unit = 1000) { 84 92 std::string::size_type p = time.find_first_of("sSmMhHdDwW"); -
include/thread.h
r1d9338a r75d5e70 40 40 HANDLE hThread_; // Thread handle 41 41 T* pObject_; // Wrapped object 42 HANDLE hStopEvent_; // Event to signal that the thread has stopped43 42 HANDLE hMutex_; // Mutex to protect internal data 43 unsigned uThreadID; // THe thread ID 44 45 46 bool bThreadHasTerminated; 47 bool bThreadHasBeenClosed; 48 44 49 45 50 46 51 typedef struct thread_param { 47 HANDLE hStopEvent; // The stop event to signal when thread dies48 52 T *instance; // The thread instance object 49 53 LPVOID lpParam; // The optional argument to the thread … … 56 60 * Sets up default values 57 61 */ 58 Thread() : hThread_(NULL), pObject_(NULL), hStopEvent_(NULL) {62 Thread() : hThread_(NULL), pObject_(NULL), uThreadID(-1), bThreadHasTerminated(false), bThreadHasBeenClosed(false) { 59 63 hMutex_ = CreateMutex(NULL, FALSE, NULL); 60 64 assert(hMutex_ != NULL); … … 67 71 virtual ~Thread() { 68 72 { 73 if (bThreadHasBeenClosed && bThreadHasTerminated) 74 ; 75 else if (bThreadHasBeenClosed||bThreadHasTerminated) 76 std::cout << "Thread has not terminated correctly..." << std::endl; 77 /* 69 78 MutexLock mutex(hMutex_, 5000L); 70 79 if (!mutex.hasMutex()) { … … 76 85 hStopEvent_ = NULL; 77 86 delete pObject_; 78 pObject_ = NULL; 87 */ 88 // pObject_ = NULL; 89 // CloseHandle(hThread_); 79 90 } 80 91 if (hMutex_) … … 91 102 * @return exit status 92 103 */ 93 static void threadProc(LPVOIDlpParameter) {104 static unsigned __stdcall threadProc(void* lpParameter) { 94 105 thread_param* param = static_cast<thread_param*>(lpParameter); 95 106 T* instance = param->instance; 96 HANDLE hStopEvent = param->hStopEvent;97 107 LPVOID lpParam = param->lpParam; 98 108 Thread *pCore = param->pCore; 99 109 delete param; 100 110 101 instance->threadProc(lpParam);111 unsigned returnCode = instance->threadProc(lpParam); 102 112 pCore->terminate(); 103 SetEvent(hStopEvent); 104 _endthread(); 113 _endthreadex( 0 ); 114 return returnCode; 115 116 // _endthread(); 105 117 } 106 118 … … 125 137 throw ThreadException("Thread already started, thread not started..."); 126 138 } 127 assert(hStopEvent_ == NULL);139 // assert(hStopEvent_ == NULL); 128 140 param = new thread_param; 129 141 param->instance = pObject_ = new T; 130 param->hStopEvent = hStopEvent_ = CreateEvent(NULL, TRUE, FALSE, NULL);142 // param->hStopEvent = hStopEvent_ = CreateEvent(NULL, TRUE, FALSE, NULL); 131 143 param->lpParam = lpParam; 132 144 param->pCore = this; 133 145 } 134 hThread_ = reinterpret_cast<HANDLE>(::_beginthread(threadProc, 0, reinterpret_cast<VOID*>(param))); 146 //hThread_ = reinterpret_cast<HANDLE>(::_beginthreadex(threadProc, 0, reinterpret_cast<VOID*>(param))); 147 //hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0, &threadID ); 148 hThread_ = reinterpret_cast<HANDLE>(::_beginthreadex(NULL, 0, threadProc, reinterpret_cast<VOID*>(param), 0, &uThreadID)); 135 149 } 136 150 /** … … 139 153 * @return true if the thread has terminated 140 154 */ 141 bool exitThread(const unsigned int delay = 5000L) {155 bool exitThread(const unsigned int delay = 20000L) { 142 156 DWORD dwWaitResult = -1; 143 157 { 144 MutexLock mutex(hMutex_, 5000L);158 MutexLock mutex(hMutex_, delay); 145 159 if (!mutex.hasMutex()) { 146 160 throw ThreadException("Could not retrieve mutex, thread not stopped..."); … … 148 162 if (!pObject_) 149 163 return true; 150 assert(hStopEvent_ != NULL);151 164 pObject_->exitThread(); 152 165 } 153 dwWaitResult = WaitForSingleObject(hStopEvent_, delay); 154 switch (dwWaitResult) { 155 // The thread got mutex ownership. 156 case WAIT_OBJECT_0: 157 return true; 158 // Did not get a signal due to time-out. 159 case WAIT_TIMEOUT: 160 return false; 161 // Never got a signal. 162 case WAIT_ABANDONED: 163 return false; 164 } 166 dwWaitResult = WaitForSingleObject(hThread_, delay); 167 if (dwWaitResult == WAIT_OBJECT_0) { 168 bThreadHasBeenClosed = true; 169 CloseHandle(hThread_); 170 delete pObject_; 171 pObject_ = NULL; 172 return true; 173 } 174 std::cout << "Failed to terminate thread..." << std::endl; 175 assert(false); 165 176 return false; 166 177 } … … 188 199 private: 189 200 void terminate() { 190 MutexLock mutex(hMutex_, 5000L); 191 if (!mutex.hasMutex()) { 192 throw ThreadException("Could not retrieve mutex, thread not stopped..."); 193 } 194 delete pObject_; 195 pObject_ = NULL; 196 hThread_ = NULL; 201 bThreadHasTerminated = true; 197 202 } 198 203 }; -
include/utils.h
re26cfe0 r75d5e70 30 30 } 31 31 32 33 34 35 36 37 38 32 #define MAP_OPTIONS_BEGIN(args) \ 39 33 for (std::list<std::string>::const_iterator cit__=args.begin();cit__!=args.end();++cit__) { \ 40 34 std::pair<std::string,std::string> p__ = strEx::split(*cit__,"="); if (false) {} 35 36 #define MAP_OPTIONS_SHOWALL(obj) \ 37 else if (p__.first == SHOW_ALL) { if (p__.second == "long") obj.show = checkHolders::showLong; else obj.show = checkHolders::showShort; } \ 38 else if (p__.first == SHOW_FAIL) { obj.show = checkHolders::showProblems; } 39 40 #define MAP_OPTIONS_DISK_ALL(obj, postfix, pfUpper, pfLower) \ 41 else if (p__.first == "MaxWarn" pfUpper) { obj.warn.max.upper = p__.second; } \ 42 else if (p__.first == "MaxCrit" pfUpper) { obj.crit.max.upper = p__.second; } \ 43 else if (p__.first == "MinWarn" pfUpper) { obj.warn.min.upper = p__.second; } \ 44 else if (p__.first == "MinCrit" pfUpper) { obj.crit.min.upper = p__.second; } \ 45 else if (p__.first == "MaxWarn" pfLower) { obj.warn.max.lower = p__.second; } \ 46 else if (p__.first == "MaxCrit" pfLower) { obj.crit.max.lower = p__.second; } \ 47 else if (p__.first == "MinWarn" pfLower) { obj.warn.min.lower = p__.second; } \ 48 else if (p__.first == "MinCrit" pfLower) { obj.crit.min.lower = p__.second; } \ 49 else if (p__.first == "MaxWarn" postfix) { obj.warn.max.lower = p__.second; } \ 50 else if (p__.first == "MaxCrit" postfix) { obj.crit.max.lower = p__.second; } \ 51 else if (p__.first == "MinWarn" postfix) { obj.warn.min.upper = p__.second; } \ 52 else if (p__.first == "MinCrit" postfix) { obj.crit.min.upper = p__.second; } 53 54 #define MAP_OPTIONS_NUMERIC_ALL(obj, postfix) \ 55 else if (p__.first == ("MaxWarn" postfix)) { obj.warn.max = p__.second; } \ 56 else if (p__.first == ("MaxCrit" postfix)) { obj.crit.max = p__.second; } \ 57 else if (p__.first == ("MinWarn" postfix)) { obj.warn.min = p__.second; } \ 58 else if (p__.first == ("MinCrit" postfix)) { obj.crit.min = p__.second; } 59 60 #define MAP_OPTIONS_PUSH(value, list) \ 61 else if (p__.first == value) { list.push_back(p__.second); } 62 #define MAP_OPTIONS_DO(action) \ 63 else if (p__.first == value) { action; } 41 64 #define MAP_OPTIONS_STR(value, obj) \ 42 65 else if (p__.first == value) { obj = p__.second; } 66 #define MAP_OPTIONS_STR2INT(value, obj) \ 67 else if (p__.first == value) { obj = atoi(p__.second.c_str()); } 43 68 #define MAP_OPTIONS_STR_AND(value, obj, extra) \ 44 69 else if (p__.first == value) { obj = p__.second; extra;} … … 47 72 #define MAP_OPTIONS_BOOL_FALSE(value, obj) \ 48 73 else if (p__.first == value) { obj = false; } 74 #define MAP_OPTIONS_BOOL_VALUE(value, obj, tStr) \ 75 else if ((p__.first == value)&&(p__.second == tStr)) { obj = true; } 49 76 #define MAP_OPTIONS_BOOL_EX(value, obj, tStr, fStr) \ 50 77 else if ((p__.first == value)&&(p__.second == tStr)) { obj = true; } \ 51 78 else if ((p__.first == value)&&(p__.second == fStr)) { obj = false; } 52 79 #define MAP_OPTIONS_MISSING(arg, str) \ 53 else { arg = str + p__.first; return NSCAPI::returnUNKNOWN; } 80 else { arg = str + p__.first; return NSCAPI::returnUNKNOWN; } 81 #define MAP_OPTIONS_FALLBACK_AND(obj, extra) \ 82 else { obj = p__.first; extra;} 54 83 #define MAP_OPTIONS_END() } 55 84 -
modules/CheckDisk/CheckDisk.cpp
re26cfe0 r75d5e70 87 87 88 88 DriveConatiner tmpObject; 89 bool bShowAll = false;90 89 bool bFilter = false; 91 90 bool bFilterRemote = false; … … 99 98 MAP_OPTIONS_BEGIN(args) 100 99 MAP_OPTIONS_STR_AND("Drive", tmpObject.data, drives.push_back(tmpObject)) 101 MAP_OPTIONS_STR("MaxWarn", tmpObject.warn.max) 102 MAP_OPTIONS_STR("MinWarn", tmpObject.warn.min) 103 MAP_OPTIONS_STR("MaxCrit", tmpObject.crit.max) 104 MAP_OPTIONS_STR("MinCrit", tmpObject.crit.min) 105 else if (p__.first == "FilterType") { 106 bFilter = true; 107 if (p__.second == "FIXED") { 108 bFilterFixed = true; 109 } else if (p__.second == "CDROM") { 110 bFilterCDROM = true; 111 } else if (p__.second == "REMOVABLE") { 112 bFilterRemovable = true; 113 } else if (p__.second == "REMOTE") { 114 bFilterRemote= true; 115 } 116 } 100 MAP_OPTIONS_DISK_ALL(tmpObject, "", "Free", "Used") 101 MAP_OPTIONS_SHOWALL(tmpObject) 102 MAP_OPTIONS_BOOL_VALUE("FilterType", bFilterFixed, "FIXED") 103 MAP_OPTIONS_BOOL_VALUE("FilterType", bFilterCDROM, "CDROM") 104 MAP_OPTIONS_BOOL_VALUE("FilterType", bFilterRemovable, "REMOVABLE") 105 MAP_OPTIONS_BOOL_VALUE("FilterType", bFilterRemote, "REMOTE") 117 106 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 118 MAP_OPTIONS_BOOL_TRUE(SHOW_ALL, bShowAll)119 107 MAP_OPTIONS_BOOL_TRUE(CHECK_ALL, bCheckAll) 120 108 MAP_OPTIONS_SECONDARY_BEGIN(":", p2) … … 126 114 MAP_OPTIONS_MISSING_EX(p2, message, "Unknown argument: ") 127 115 MAP_OPTIONS_SECONDARY_END() 128 MAP_OPTIONS_MISSING(message, "Unknown argument: ")116 MAP_OPTIONS_FALLBACK_AND(tmpObject.data, drives.push_back(tmpObject)) 129 117 MAP_OPTIONS_END() 118 bFilter = bFilterFixed || bFilterCDROM || bFilterRemote || bFilterRemovable; 130 119 131 120 if (bCheckAll) { … … 182 171 message += strEx::itos(totalNumberOfBytes.QuadPart); 183 172 } else { 173 checkHolders::PercentageValueType<checkHolders::disk_size_type, checkHolders::disk_size_type> value; 184 174 std::string tstr; 185 checkHolders::disk_size_type size = totalNumberOfBytes.QuadPart-totalNumberOfFreeBytes.QuadPart; 175 value.value = totalNumberOfBytes.QuadPart-totalNumberOfFreeBytes.QuadPart; 176 value.total = totalNumberOfBytes.QuadPart; 186 177 drive.setDefault(tmpObject); 187 drive.warn.max.setMax(totalNumberOfBytes.QuadPart); 188 drive.warn.min.setMax(totalNumberOfBytes.QuadPart); 189 drive.crit.max.setMax(totalNumberOfBytes.QuadPart); 190 drive.crit.min.setMax(totalNumberOfBytes.QuadPart); 191 drive.runCheck(size, returnCode, message, perf, bShowAll); 178 drive.runCheck(value, returnCode, message, perf); 192 179 } 193 180 } … … 209 196 } 210 197 PathConatiner tmpObject; 211 bool bShowAll = false;212 198 std::list<PathConatiner> paths; 213 199 214 200 MAP_OPTIONS_BEGIN(args) 215 201 MAP_OPTIONS_STR_AND("File", tmpObject.data, paths.push_back(tmpObject)) 202 MAP_OPTIONS_SHOWALL(tmpObject) 216 203 MAP_OPTIONS_STR("MaxWarn", tmpObject.warn.max) 217 204 MAP_OPTIONS_STR("MinWarn", tmpObject.warn.min) 218 205 MAP_OPTIONS_STR("MaxCrit", tmpObject.crit.max) 219 206 MAP_OPTIONS_STR("MinCrit", tmpObject.crit.min) 220 MAP_OPTIONS_BOOL_TRUE(SHOW_ALL, bShowAll)221 207 MAP_OPTIONS_SECONDARY_BEGIN(":", p2) 222 208 else if (p2.first == "File") { … … 239 225 240 226 checkHolders::disk_size_type size = sizeFinder.getSize(); 241 path.runCheck(size, returnCode, message, perf , bShowAll);227 path.runCheck(size, returnCode, message, perf); 242 228 } 243 229 if (message.empty()) -
modules/CheckDisk/CheckDisk.vcproj
rcea178b r75d5e70 228 228 </File> 229 229 <File 230 RelativePath="..\..\include\checkHelpers.hpp"> 231 </File> 232 <File 230 233 RelativePath="..\..\include\NSCHelper.h"> 231 234 </File> -
modules/CheckEventLog/CheckEventLog.cpp
re26cfe0 r75d5e70 6 6 #include <strEx.h> 7 7 #include <time.h> 8 #include <utils.h> 8 9 9 10 CheckEventLog gCheckEventLog; … … 39 40 class EventLogRecord { 40 41 EVENTLOGRECORD *pevlr_; 42 DWORD currentTime_; 41 43 public: 42 EventLogRecord(EVENTLOGRECORD *pevlr ) : pevlr_(pevlr) {44 EventLogRecord(EVENTLOGRECORD *pevlr, DWORD currentTime) : pevlr_(pevlr), currentTime_(currentTime) { 43 45 } 44 46 inline DWORD timeGenerated() const { 45 return pevlr_->TimeGenerated;47 return (currentTime_-pevlr_->TimeGenerated)*1000; 46 48 } 47 49 inline DWORD timeWritten() const { 48 return pevlr_->TimeWritten;50 return (currentTime_-pevlr_->TimeWritten)*1000; 49 51 } 50 52 inline std::string eventSource() const { … … 121 123 122 124 123 struct searchQuery { 124 struct searchQueryItem { 125 126 typedef enum { 127 eventType, 128 eventSource, 129 timeWritten, 130 timeGenerated, 131 message, 132 none 133 } queryType; 134 135 typedef enum { out, in, undefined } filterType; 136 137 filterType filter_; 138 queryType queryType_; 139 DWORD dwValue_; 140 boost::regex regexp_; 141 142 143 searchQueryItem() 144 : queryType_(none), dwValue_(0), filter_(out) 145 {} 146 searchQueryItem(filterType filter, queryType type, std::string str) 147 : queryType_(type), dwValue_(0), filter_(filter) 148 { 149 switch (queryType_ ) { 150 case eventType: 151 dwValue_ = EventLogRecord::translateType(str); 152 break; 153 154 case timeGenerated: 155 dwValue_ = strEx::stoui_as_time(str)/1000; 156 break; 157 158 case eventSource: 159 case message: 160 try { 161 regexp_ = str; 162 } catch (const boost::bad_expression e) { 163 throw (std::string)"Invalid syntax in regular expression:" + str; 164 } 165 break; 166 } 167 } 168 169 searchQueryItem& operator=(const searchQueryItem &other) { 170 queryType_ = other.queryType_; 171 dwValue_ = other.dwValue_; 172 filter_ = other.filter_; 173 try { 174 regexp_ = other.regexp_; 175 } catch (const boost::bad_expression e) { 176 throw (std::string)"Invalid syntax in regular expression:" + other.toString(); 177 } 178 return *this; 179 } 180 181 bool match(DWORD now, const EventLogRecord &record) const { 182 switch (queryType_) { 183 case eventType: 184 return record.eventType() & dwValue_; 185 186 case eventSource: 187 if (regexp_.empty()) 188 return false; 189 return boost::regex_match(record.eventSource(), regexp_); 190 191 case timeWritten: 192 return record.timeWritten() < (now-dwValue_); 193 194 case timeGenerated: 195 return record.timeGenerated() < (now-dwValue_); 196 197 case message: 198 if (regexp_.empty()) 199 return false; 200 return boost::regex_match(record.enumStrings(), regexp_); 201 202 default: 203 return false; 204 } 205 } 206 std::string queryType2String(queryType query) const { 207 switch (queryType_) { 208 case eventType: 209 return "eventType"; 210 case eventSource: 211 return "eventSource"; 212 case timeWritten: 213 return "timeWritten"; 214 case timeGenerated: 215 return "timeGenerated"; 216 case message: 217 return "message"; 218 default: 219 return "unknown"; 220 } 221 222 } 223 224 std::string toString() const { 225 std::stringstream ss; 226 ss << " Type: " << queryType2String(queryType_) << " = " << dwValue_ << ", '" << regexp_ << "'"; 227 return ss.str(); 228 } 229 }; 230 231 232 233 unsigned int truncate; 234 unsigned warning_count; 235 unsigned critical_count; 236 bool descriptions; 237 std::list<searchQueryItem> queries; 238 239 searchQuery() : truncate(0), descriptions(false), warning_count(0), critical_count(0) {} 240 241 std::string toString() { 242 std::string ret; 243 for (std::list<searchQuery::searchQueryItem>::const_iterator cit = queries.begin(); cit != queries.end(); ++cit ) { 244 ret += (*cit).toString(); 245 } 246 return ret; 247 } 248 125 struct eventlog_filter { 126 filters::filter_all_strings eventSource; 127 filters::filter_all_numeric<unsigned int, filters::handlers::eventtype_handler> eventType; 128 filters::filter_all_strings message; 129 filters::filter_all_times timeWritten; 130 filters::filter_all_times timeGenerated; 131 132 inline bool hasFilter() { 133 return eventSource.hasFilter() || eventType.hasFilter() || message.hasFilter() || 134 timeWritten.hasFilter() || timeGenerated.hasFilter(); 135 } 136 bool matchFilter(const EventLogRecord &value) const { 137 if ((eventSource.hasFilter())&&(eventSource.matchFilter(value.eventSource()))) 138 return true; 139 else if ((eventType.hasFilter())&&(eventType.matchFilter(value.eventType()))) 140 return true; 141 else if ((message.hasFilter())&&(message.matchFilter(value.enumStrings()))) 142 return true; 143 else if ((timeWritten.hasFilter())&&(timeWritten.matchFilter(value.timeWritten()))) 144 return true; 145 else if ((timeGenerated.hasFilter())&&(timeGenerated.matchFilter(value.timeGenerated()))) 146 return true; 147 return false; 148 } 249 149 }; 250 150 251 // checkEventLog file=application truncate=1024 descriptions filter=[out|in] 252 // warning-count=3 critical-count=10 253 // filter type = warning AND generated > 1d 254 // 255 // match (type, "warning") && match(generated, "1d") 256 // filer-eventType=warning 257 // filer-eventSource= 258 // filer-date=4d 259 // 260 // CheckEventLog 261 // request: CheckEventLog&<logfile>&<Query strings> 262 // Return: <return state>&<log entry 1> - <log entry 2>... 263 // <return state> 0 - No errors 264 // 1 - Unknown 265 // 2 - Errors 266 267 // ./nrpe-2.0/src/check_nrpe -H 192.168.167 -p 5666 -c checkEventLog -a file=system file=application filter-eventType=warning filter-generated=1d descriptions filter-eventSource=Cdrom filter-eventSource=NSClient warning-count=3 critical-count=7 filter=in truncate=512 268 // 269 // Examples: 270 // CheckEventLog&Application&1&<type>&<query>&huffa... 271 // CheckEventLog&Application&warn.require.eventType=warning&critical.require.eventType=error&truncate=1024&descriptions&all.exclude.eventSourceRegexp=^(Win|Msi|NSClient\+\+|Userenv|ASP\.NET|LoadPerf|Outlook|Application E|NSClient).* 151 152 #define MAP_FILTER(value, obj) \ 153 else if (p__.first == value) { eventlog_filter filter; filter.obj = p__.second; filter_chain.push_back(filter); } 154 155 272 156 #define BUFFER_SIZE 1024*64 273 157 NSCAPI::nagiosReturn CheckEventLog::handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 274 158 if (command != "CheckEventLog") 275 159 return NSCAPI::returnIgnored; 276 NSCAPI::nagiosReturn rCode = NSCAPI::returnOK; 277 std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args); 278 279 std::string ret; 280 searchQuery query; 160 typedef checkHolders::CheckConatiner<checkHolders::MaxMinBoundsUInteger> EventLogQueryConatiner; 161 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 162 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 163 281 164 std::list<std::string> files; 282 searchQuery::searchQueryItem::filterType filter = searchQuery::searchQueryItem::out; 283 284 for (std::list<std::string>::const_iterator it = args.begin(); it!=args.end(); ++it) { 285 try { 286 if ((*it) == "descriptions") { 287 query.descriptions = true; 288 } else { 289 std::pair<std::string,std::string> p = strEx::split((*it), "="); 290 if (p.first == "truncate") { 291 query.truncate = strEx::stoi(p.second); 292 } else if (p.first == "file") { 293 files.push_back(p.second); 294 } else if (p.first == "filter") { 295 if (p.second == "in") 296 filter = searchQuery::searchQueryItem::in; 297 else 298 filter = searchQuery::searchQueryItem::out; 299 } else if (p.first == "warning-count") { 300 query.warning_count = strEx::stoi(p.second); 301 } else if (p.first == "critical-count") { 302 query.critical_count = strEx::stoi(p.second); 303 304 } else if (p.first == "filter-eventType") { 305 query.queries.push_back(searchQuery::searchQueryItem(filter, searchQuery::searchQueryItem::eventType, p.second)); 306 } else if (p.first == "filter-eventSource") { 307 query.queries.push_back(searchQuery::searchQueryItem(filter, searchQuery::searchQueryItem::eventSource, p.second)); 308 } else if (p.first == "filter-generated") { 309 query.queries.push_back(searchQuery::searchQueryItem(filter, searchQuery::searchQueryItem::timeGenerated, p.second)); 310 } else if (p.first == "filter-written") { 311 query.queries.push_back(searchQuery::searchQueryItem(filter, searchQuery::searchQueryItem::timeWritten, p.second)); 312 } else if (p.first == "filter-message") { 313 query.queries.push_back(searchQuery::searchQueryItem(filter, searchQuery::searchQueryItem::message, p.second)); 314 } 315 } 316 } catch (std::string s) { 317 if (message.empty()) 318 message += "UNKNOWN: "; 319 else 320 message += ", "; 321 message += s; 322 } 323 } 324 if (!message.empty()) { 165 std::list<eventlog_filter> filter_chain; 166 EventLogQueryConatiner query; 167 168 bool bFilterIn = true; 169 bool bFilterAll = false; 170 bool bShowDescriptions = false; 171 unsigned int truncate = 0; 172 173 try { 174 MAP_OPTIONS_BEGIN(stl_args) 175 MAP_OPTIONS_NUMERIC_ALL(query, "") 176 MAP_OPTIONS_STR2INT("truncate", truncate) 177 MAP_OPTIONS_BOOL_TRUE("descriptions", bShowDescriptions) 178 MAP_OPTIONS_PUSH("file", files) 179 MAP_OPTIONS_BOOL_EX("filter", bFilterIn, "in", "out") 180 MAP_OPTIONS_BOOL_EX("filter", bFilterAll, "all", "any") 181 MAP_FILTER("filter-eventType", eventType) 182 MAP_FILTER("filter-eventSource", eventSource) 183 MAP_FILTER("filter-generated", timeGenerated) 184 MAP_FILTER("filter-written", timeWritten) 185 MAP_FILTER("filter-message", message) 186 MAP_OPTIONS_MISSING(message, "Unknown argument: ") 187 MAP_OPTIONS_END() 188 } catch (filters::parse_exception e) { 189 message = e.getMessage(); 190 return NSCAPI::returnUNKNOWN; 191 } catch (filters::filter_exception e) { 192 message = e.getMessage(); 325 193 return NSCAPI::returnUNKNOWN; 326 194 } … … 352 220 while (dwRead > 0) 353 221 { 354 bool match = false; 355 bool undefined = true; 356 searchQuery::searchQueryItem::filterType tFilter = searchQuery::searchQueryItem::out; 357 EventLogRecord record(pevlr); 358 359 for (std::list<searchQuery::searchQueryItem>::const_iterator cit3 = query.queries.begin(); cit3 != query.queries.end(); ++cit3 ) { 360 if ((*cit3).match(currentTime, record)) { 361 if ((*cit3).filter_ == searchQuery::searchQueryItem::in) 362 match = true; 363 else { 364 match = false; 222 bool bMatch = bFilterAll; 223 EventLogRecord record(pevlr, currentTime); 224 225 for (std::list<eventlog_filter>::const_iterator cit3 = filter_chain.begin(); cit3 != filter_chain.end(); ++cit3 ) { 226 bool bTmpMatched = (*cit3).matchFilter(record); 227 if (bFilterAll) { 228 if (!bTmpMatched) { 229 bMatch = false; 230 break; 231 } 232 } else { 233 if (bTmpMatched) { 234 bMatch = true; 235 break; 365 236 } 366 237 } 367 238 } 368 239 369 if (match) { 370 if (!ret.empty()) 371 ret += ", "; 372 ret += record.eventSource(); 373 if (query.descriptions) { 374 ret += "(" + EventLogRecord::translateType(record.eventType()) + ")"; 375 ret += "[" + record.enumStrings() + "]"; 240 if ((bFilterIn&&bMatch)||(!bFilterIn&&!bMatch)) { 241 strEx::append_list(message, record.eventSource()); 242 if (bShowDescriptions) { 243 message += "(" + EventLogRecord::translateType(record.eventType()) + ")"; 244 message += "[" + record.enumStrings() + "]"; 376 245 } 377 246 hit_count++; 378 247 } 379 380 248 dwRead -= pevlr->Length; 381 249 pevlr = (EVENTLOGRECORD *) ((LPBYTE) pevlr + pevlr->Length); 382 250 } 383 384 251 pevlr = (EVENTLOGRECORD *) &bBuffer; 385 252 } 386 387 253 CloseEventLog(hLog); 388 254 } 389 390 if ((query.critical_count > 0) && (hit_count > query.critical_count)) { 391 ret = "CRITICAL: " + strEx::itos(hit_count) + " > critical: " + ret; 392 rCode = NSCAPI::returnCRIT; 393 } else if ((query.warning_count > 0) && (hit_count > query.warning_count)) { 394 ret = "WARNING: " + strEx::itos(hit_count) + " > warning: " + ret; 395 rCode = NSCAPI::returnWARN; 396 } else { 397 ret = "OK: " + strEx::itos(hit_count) + ": " + ret; 398 } 399 if (query.truncate != 0) 400 ret = ret.substr(0, query.truncate); 401 if ((query.truncate > 0) && (ret.length() > query.truncate)) 402 ret = ret.substr(0, query.truncate); 403 message = ret; 404 return rCode; 255 query.runCheck(hit_count, returnCode, message, perf); 256 if ((truncate > 0) && (message.length() > (truncate-4))) 257 message = message.substr(0, truncate-4) + "..."; 258 if (message.empty()) 259 message = "Eventlog check ok"; 260 return returnCode; 405 261 } 406 262 -
modules/CheckEventLog/CheckEventLog.h
re26cfe0 r75d5e70 2 2 3 3 #include <strEx.h> 4 #include <checkHelpers.hpp> 5 #include <filter_framework.hpp> 4 6 5 7 class CheckEventLog { -
modules/CheckSystem/CheckSystem.cpp
re26cfe0 r75d5e70 148 148 std::list<CPULoadConatiner> list; 149 149 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 150 bool bShowAll = false;151 150 bool bNSClient = false; 152 151 CPULoadConatiner tmpObject; … … 155 154 156 155 MAP_OPTIONS_BEGIN(stl_args) 157 MAP_OPTIONS_ STR("MaxWarn", tmpObject.warn.max)156 MAP_OPTIONS_NUMERIC_ALL(tmpObject, "") 158 157 MAP_OPTIONS_STR("warn", tmpObject.warn.max) 159 MAP_OPTIONS_STR("MinWarn", tmpObject.warn.min)160 MAP_OPTIONS_STR("MaxCrit", tmpObject.crit.max)161 158 MAP_OPTIONS_STR("crit", tmpObject.crit.max) 162 MAP_OPTIONS_STR("MinCrit", tmpObject.crit.min)163 159 MAP_OPTIONS_STR_AND("time", tmpObject.data, list.push_back(tmpObject)) 164 160 MAP_OPTIONS_STR_AND("Time", tmpObject.data, list.push_back(tmpObject)) 165 MAP_OPTIONS_ BOOL_TRUE(SHOW_ALL, bShowAll)161 MAP_OPTIONS_SHOWALL(tmpObject) 166 162 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 167 163 MAP_OPTIONS_SECONDARY_BEGIN(":", p2) … … 173 169 MAP_OPTIONS_MISSING_EX(p2, msg, "Unknown argument: ") 174 170 MAP_OPTIONS_SECONDARY_END() 175 else { tmpObject.data = p__.first, list.push_back(tmpObject); }171 MAP_OPTIONS_FALLBACK_AND(tmpObject.data, list.push_back(tmpObject)) 176 172 MAP_OPTIONS_END() 177 173 … … 198 194 } else { 199 195 load.setDefault(tmpObject); 200 load.runCheck(value, returnCode, msg, perf , bShowAll);196 load.runCheck(value, returnCode, msg, perf); 201 197 } 202 198 } … … 220 216 } 221 217 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 222 bool bShowAll = false;223 218 bool bNSClient = false; 224 219 UpTimeConatiner bounds; … … 227 222 228 223 MAP_OPTIONS_BEGIN(stl_args) 229 MAP_OPTIONS_ STR("MaxWarn", bounds.warn.max)224 MAP_OPTIONS_NUMERIC_ALL(bounds, "") 230 225 MAP_OPTIONS_STR("warn", bounds.warn.min) 231 MAP_OPTIONS_STR("MinWarn", bounds.warn.min)232 MAP_OPTIONS_STR("MaxCrit", bounds.crit.max)233 226 MAP_OPTIONS_STR("crit", bounds.crit.min) 234 MAP_OPTIONS_STR("MinCrit", bounds.crit.min)235 227 MAP_OPTIONS_STR("Alias", bounds.data) 236 MAP_OPTIONS_ BOOL_TRUE(SHOW_ALL, bShowAll)228 MAP_OPTIONS_SHOWALL(bounds) 237 229 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 238 230 MAP_OPTIONS_MISSING(msg, "Unknown argument: ") … … 250 242 } else { 251 243 value *= 1000; 252 bounds.runCheck(value, returnCode, msg, perf , bShowAll);244 bounds.runCheck(value, returnCode, msg, perf); 253 245 } 254 246 … … 296 288 std::list<StateConatiner> list; 297 289 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 298 bool bShowAll = false;299 290 bool bNSClient = false; 300 291 StateConatiner tmpObject; … … 304 295 305 296 MAP_OPTIONS_BEGIN(stl_args) 306 /* 307 MAP_OPTIONS_STR("MaxWarn", tmpObject.warn.max) 308 MAP_OPTIONS_STR("warn", tmpObject.warn.min) 309 MAP_OPTIONS_STR("MinWarn", tmpObject.warn.min) 310 MAP_OPTIONS_STR("MaxCrit", tmpObject.crit.max) 311 MAP_OPTIONS_STR("crit", tmpObject.crit.min) 312 MAP_OPTIONS_STR("MinCrit", tmpObject.crit.min) 313 */ 297 MAP_OPTIONS_SHOWALL(tmpObject) 314 298 MAP_OPTIONS_STR("Alias", tmpObject.data) 315 MAP_OPTIONS_BOOL_TRUE(SHOW_ALL, bShowAll)316 MAP_OPTIONS_BOOL_FALSE(SHOW_FAIL, bShowAll)317 299 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 318 300 MAP_OPTIONS_SECONDARY_BEGIN(":", p2) … … 345 327 continue; 346 328 } 347 if ((info.m_dwCurrentState == SERVICE_RUNNING) && ( bShowAll)) {329 if ((info.m_dwCurrentState == SERVICE_RUNNING) && (*it).showAll()) { 348 330 if (!msg.empty()) msg += " - "; 349 331 msg += (*it).data + ": Started"; … … 373 355 else 374 356 value = checkHolders::state_none; 375 (*it).runCheck(value, returnCode, msg, perf , bShowAll);357 (*it).runCheck(value, returnCode, msg, perf); 376 358 } 377 359 … … 398 380 NSCAPI::nagiosReturn CheckSystem::checkMem(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 399 381 { 400 typedef checkHolders::CheckConatiner<checkHolders::MaxMinPercentageBounds Int64 > MemoryConatiner;382 typedef checkHolders::CheckConatiner<checkHolders::MaxMinPercentageBoundsDiskSizei64 > MemoryConatiner; 401 383 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 402 384 if (stl_args.empty()) { … … 412 394 413 395 MAP_OPTIONS_BEGIN(stl_args) 414 MAP_OPTIONS_STR("MaxWarn", bounds.warn.max) 415 MAP_OPTIONS_STR("MinWarn", bounds.warn.min) 416 MAP_OPTIONS_STR("MaxCrit", bounds.crit.max) 417 MAP_OPTIONS_STR("MinCrit", bounds.crit.min) 396 MAP_OPTIONS_DISK_ALL(bounds, "", "Free", "Used") 418 397 MAP_OPTIONS_STR("Alias", bounds.data) 419 MAP_OPTIONS_ BOOL_TRUE(SHOW_ALL, bShowAll)398 MAP_OPTIONS_SHOWALL(bounds) 420 399 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 421 400 MAP_OPTIONS_MISSING(msg, "Unknown argument: ") … … 427 406 return NSCAPI::returnUNKNOWN; 428 407 } 429 long long pageCommit = pObject->getMemCommit(); 430 long long pageCommitLimit = pObject->getMemCommitLimit(); 408 checkHolders::PercentageValueType<long long, long long> value; 409 value.value = pObject->getMemCommit(); 410 value.total = pObject->getMemCommitLimit(); 431 411 if (bNSClient) { 432 msg = strEx::itos( pageCommitLimit) + "&" + strEx::itos(pageCommit);412 msg = strEx::itos(value.total) + "&" + strEx::itos(value.value); 433 413 return NSCAPI::returnOK; 434 414 } else { 435 bounds.warn.max.setMax(pageCommitLimit); 436 bounds.warn.min.setMax(pageCommitLimit); 437 bounds.crit.max.setMax(pageCommitLimit); 438 bounds.crit.min.setMax(pageCommitLimit); 439 bounds.runCheck(pageCommit, returnCode, msg, perf, bShowAll); 415 bounds.runCheck(value, returnCode, msg, perf); 440 416 } 441 417 if (msg.empty()) … … 500 476 std::list<StateConatiner> list; 501 477 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 502 bool bShowAll = false;503 478 bool bNSClient = false; 504 479 StateConatiner tmpObject; … … 508 483 509 484 MAP_OPTIONS_BEGIN(stl_args) 510 MAP_OPTIONS_STR("MaxWarnCount", tmpObject.warn.max) 511 MAP_OPTIONS_STR("MinWarnCount", tmpObject.warn.min) 512 MAP_OPTIONS_STR("MaxCritCount", tmpObject.crit.max) 513 MAP_OPTIONS_STR("MinCritCount", tmpObject.crit.min) 485 MAP_OPTIONS_NUMERIC_ALL(tmpObject, "Count") 514 486 MAP_OPTIONS_STR("Alias", tmpObject.alias) 515 MAP_OPTIONS_BOOL_TRUE(SHOW_ALL, bShowAll) 516 MAP_OPTIONS_BOOL_FALSE(SHOW_FAIL, bShowAll) 487 MAP_OPTIONS_SHOWALL(tmpObject) 517 488 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 518 489 MAP_OPTIONS_SECONDARY_BEGIN(":", p2) … … 550 521 TNtServiceInfo info; 551 522 if (bNSClient) { 552 if (bFound && bShowAll) {523 if (bFound && (*it).showAll()) { 553 524 if (!msg.empty()) msg += " - "; 554 525 msg += (*it).data + ": Started"; … … 568 539 value.state = checkHolders::state_stopped; 569 540 } 570 (*it).runCheck(value, returnCode, msg, perf , bShowAll);541 (*it).runCheck(value, returnCode, msg, perf); 571 542 } 572 543 … … 603 574 std::list<CounterConatiner> counters; 604 575 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 605 bool bShowAll = false;606 576 bool bNSClient = false; 607 577 /* average maax */ … … 617 587 MAP_OPTIONS_STR("MinCrit", tmpObject.crit.min) 618 588 MAP_OPTIONS_STR("Alias", tmpObject.data) 619 MAP_OPTIONS_BOOL_TRUE(SHOW_ALL, bShowAll) 620 MAP_OPTIONS_BOOL_FALSE(SHOW_FAIL, bShowAll) 589 MAP_OPTIONS_SHOWALL(tmpObject) 621 590 MAP_OPTIONS_BOOL_EX("Averages", bCheckAverages, "true", "false") 622 591 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) … … 629 598 MAP_OPTIONS_MISSING_EX(p2, msg, "Unknown argument: ") 630 599 MAP_OPTIONS_SECONDARY_END() 631 else { 632 tmpObject.data = p__.first; 633 counters.push_back(tmpObject); 634 } 600 MAP_OPTIONS_FALLBACK_AND(tmpObject.data, counters.push_back(tmpObject)) 635 601 MAP_OPTIONS_END() 636 602 … … 657 623 } else { 658 624 counter.setDefault(tmpObject); 659 counter.runCheck(value, returnCode, msg, perf , bShowAll);625 counter.runCheck(value, returnCode, msg, perf); 660 626 } 661 627 } catch (const PDH::PDHException e) { -
modules/CheckSystem/PDHCollector.cpp
re26cfe0 r75d5e70 133 133 }while (((waitStatus = WaitForSingleObject(hStopEvent_, checkIntervall_*100)) == WAIT_TIMEOUT)); 134 134 if (waitStatus != WAIT_OBJECT_0) { 135 NSC_LOG_ERROR("Something odd happen d, terminating PDH collection thread!");135 NSC_LOG_ERROR("Something odd happened, terminating PDH collection thread!"); 136 136 } 137 137 … … 142 142 } 143 143 144 if (!CloseHandle(hStopEvent_)) 144 if (!CloseHandle(hStopEvent_)) { 145 145 NSC_LOG_ERROR_STD("Failed to close stopEvent handle: " + strEx::itos(GetLastError())); 146 else146 } else 147 147 hStopEvent_ = NULL; 148 148 try { … … 160 160 */ 161 161 void PDHCollector::exitThread(void) { 162 MutexLock mutex(mutexHandler);163 if (!mutex.hasMutex()) {164 NSC_LOG_ERROR("Failed to get Mute when trying to close thread!");165 return;166 }167 162 if (hStopEvent_ == NULL) 168 NSC_LOG_ERROR(" Failed to get stop event!");163 NSC_LOG_ERROR("Stop event is not created!"); 169 164 else 170 165 if (!SetEvent(hStopEvent_)) { -
modules/SysTray/TrayIcon.cpp
re26cfe0 r75d5e70 5 5 #include <ShellAPI.h> 6 6 7 void IconWidget_::threadProc(LPVOID lpParameter)7 unsigned IconWidget_::threadProc(LPVOID lpParameter) 8 8 { 9 9 createDialog(); 10 return 0; 10 11 } 11 12 -
modules/SysTray/TrayIcon.h
re26cfe0 r75d5e70 8 8 class IconWidget_ { 9 9 public: 10 void threadProc(LPVOID lpParameter);10 unsigned threadProc(LPVOID lpParameter); 11 11 void exitThread(void); 12 12
Note: See TracChangeset
for help on using the changeset viewer.








