source: nscp/trunk/modules/CheckDisk/CheckDisk.cpp @ 3c35ad4

Last change on this file since 3c35ad4 was 3c35ad4, checked in by Michael Medin <michael@…>, 6 years ago

+ Added possibility to check many memory checks in one go, just stack type options.

type=paged type=physical etc...

  • Fixed a performance check bug in the last nightly.
  • Fixed a potential crash when a maleformed check-file-age command was issued. + Added support for more then and NSClient command
  • Property mode set to 100644
File size: 18.6 KB
Line 
1// CheckEventLog.cpp : Defines the entry point for the DLL application.
2//
3
4#include "stdafx.h"
5#include "CheckDisk.h"
6#include <strEx.h>
7#include <time.h>
8#include <filter_framework.hpp>
9
10
11
12CheckDisk gCheckDisk;
13
14BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
15{
16        NSCModuleWrapper::wrapDllMain(hModule, ul_reason_for_call);
17        return TRUE;
18}
19
20CheckDisk::CheckDisk() {
21}
22CheckDisk::~CheckDisk() {
23}
24
25
26bool CheckDisk::loadModule() {
27        return true;
28}
29bool CheckDisk::unloadModule() {
30        return true;
31}
32
33bool CheckDisk::hasCommandHandler() {
34        return true;
35}
36bool CheckDisk::hasMessageHandler() {
37        return false;
38}
39
40struct file_finder_data {
41        file_finder_data(const WIN32_FIND_DATA wfd_, const std::string path_) : wfd(wfd_), path(path_) {}
42        const WIN32_FIND_DATA wfd;
43        const std::string path;
44};
45typedef std::unary_function<const file_finder_data&, bool> baseFinderFunction;
46
47struct get_size : public baseFinderFunction
48{
49        bool error;
50        get_size() : size(0), error(false) { }
51        result_type operator()(argument_type ffd) {
52                if (!(ffd.wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) {
53                        size += (ffd.wfd.nFileSizeHigh * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)ffd.wfd.nFileSizeLow;
54                }
55                return true;
56        }
57        inline unsigned long long getSize() {
58                return size;
59        }
60        inline const bool hasError() const {
61                return error;
62        }
63        inline void setError(std::string) {
64                error = true;
65        }
66private: 
67        unsigned long long size;
68};
69
70
71template <class finder_function>
72void recursive_scan(std::string dir, finder_function & f) {
73        std::string baseDir;
74        std::string::size_type pos = dir.find_last_of('\\');
75        if (pos == std::string::npos)
76                return;
77        baseDir = dir.substr(0, pos);
78
79        WIN32_FIND_DATA wfd;
80        HANDLE hFind = FindFirstFile(dir.c_str(), &wfd);
81        if (hFind != INVALID_HANDLE_VALUE) {
82                do {
83                        if (!f(file_finder_data(wfd, baseDir)))
84                                break;
85                        if ((wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) {
86                                if ( (strcmp(wfd.cFileName, ".") != 0) && (strcmp(wfd.cFileName, "..") != 0) )
87                                        recursive_scan<finder_function>(baseDir + "\\" + wfd.cFileName + "\\*.*", f);
88                        }
89                } while (FindNextFile(hFind, &wfd));
90        } else {
91                f.setError("File not found");
92        }
93        FindClose(hFind);
94}
95
96
97
98NSCAPI::nagiosReturn CheckDisk::CheckDriveSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) {
99        NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK;
100        std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args);
101        if (args.empty()) {
102                message = "Missing argument(s).";
103                return NSCAPI::returnCRIT;
104        }
105
106        DriveConatiner tmpObject;
107        bool bFilter = false;
108        bool bFilterRemote = false;
109        bool bFilterRemovable = false;
110        bool bFilterFixed = false;
111        bool bFilterCDROM = false;
112        bool bCheckAll = false;
113        bool bCheckAllOthers = false;
114        bool bNSClient = false;
115        bool bPerfData = true;
116        std::list<DriveConatiner> drives;
117
118        MAP_OPTIONS_BEGIN(args)
119                MAP_OPTIONS_STR_AND("Drive", tmpObject.data, drives.push_back(tmpObject))
120                MAP_OPTIONS_DISK_ALL(tmpObject, "", "Free", "Used")
121                MAP_OPTIONS_SHOWALL(tmpObject)
122                MAP_OPTIONS_BOOL_VALUE("FilterType", bFilterFixed, "FIXED")
123                MAP_OPTIONS_BOOL_VALUE("FilterType", bFilterCDROM, "CDROM")
124                MAP_OPTIONS_BOOL_VALUE("FilterType", bFilterRemovable, "REMOVABLE")
125                MAP_OPTIONS_BOOL_VALUE("FilterType", bFilterRemote, "REMOTE")
126                MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData)
127                MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient)
128                MAP_OPTIONS_BOOL_TRUE(CHECK_ALL, bCheckAll)
129                MAP_OPTIONS_BOOL_TRUE(CHECK_ALL_OTHERS, bCheckAllOthers)
130                MAP_OPTIONS_SECONDARY_BEGIN(":", p2)
131                        else if (p2.first == "Drive") {
132                                tmpObject.data = p__.second;
133                                tmpObject.alias = p2.second;
134                                drives.push_back(tmpObject);
135                        }
136                        MAP_OPTIONS_MISSING_EX(p2, message, "Unknown argument: ")
137                MAP_OPTIONS_SECONDARY_END()
138        MAP_OPTIONS_FALLBACK_AND(tmpObject.data, drives.push_back(tmpObject))
139        MAP_OPTIONS_END()
140        bFilter = bFilterFixed || bFilterCDROM  || bFilterRemote || bFilterRemovable;
141
142        if (bCheckAll) {
143                DWORD dwDrives = GetLogicalDrives();
144                int idx = 0;
145                while (dwDrives != 0) {
146                        if (dwDrives & 0x1) {
147                                std::string drv;
148                                drv += static_cast<char>('A' + idx); drv += ":\\";
149                                UINT drvType = GetDriveType(drv.c_str());
150                                if ( ((!bFilter)&&(drvType == DRIVE_FIXED))  ||
151                                        ((bFilter)&&(bFilterFixed)&&(drvType==DRIVE_FIXED)) ||
152                                        ((bFilter)&&(bFilterCDROM)&&(drvType==DRIVE_CDROM)) ||
153                                        ((bFilter)&&(bFilterRemote)&&(drvType==DRIVE_REMOTE)) ||
154                                        ((bFilter)&&(bFilterRemovable)&&(drvType==DRIVE_REMOVABLE)) )
155                                        drives.push_back(DriveConatiner(drv, tmpObject.warn, tmpObject.crit));
156                        }
157                        idx++;
158                        dwDrives >>= 1;
159                }
160        }
161        if (bCheckAllOthers) {
162                std::list<DriveConatiner> checkdrives;
163                DWORD dwDrives = GetLogicalDrives();
164                int idx = 0;
165                while (dwDrives != 0) {
166                        if (dwDrives & 0x1) {
167                                std::string drv;
168                                drv += static_cast<char>('A' + idx); drv += ":\\";
169                                UINT drvType = GetDriveType(drv.c_str());
170                                if ( ((!bFilter)&&(drvType == DRIVE_FIXED))  ||
171                                        ((bFilter)&&(bFilterFixed)&&(drvType==DRIVE_FIXED)) ||
172                                        ((bFilter)&&(bFilterCDROM)&&(drvType==DRIVE_CDROM)) ||
173                                        ((bFilter)&&(bFilterRemote)&&(drvType==DRIVE_REMOTE)) ||
174                                        ((bFilter)&&(bFilterRemovable)&&(drvType==DRIVE_REMOVABLE)) ) 
175                                {
176                                        bool bFound = false;
177                                        for (std::list<DriveConatiner>::const_iterator pit = drives.begin();pit!=drives.end();++pit) {
178                                                DriveConatiner drive = (*pit);
179                                                if (drive.data == drv)
180                                                        bFound = true;
181                                        }
182                                        if (!bFound)
183                                                checkdrives.push_back(DriveConatiner(drv, tmpObject.warn, tmpObject.crit));
184                                }
185                        }
186                        idx++;
187                        dwDrives >>= 1;
188                }
189                drives = checkdrives;
190        }
191
192
193        for (std::list<DriveConatiner>::const_iterator pit = drives.begin();pit!=drives.end();++pit) {
194                DriveConatiner drive = (*pit);
195                if (drive.data.length() == 1)
196                        drive.data += ":";
197                drive.perfData = bPerfData;
198                UINT drvType = GetDriveType(drive.data.c_str());
199
200                if ((!bFilter)&&!((drvType == DRIVE_FIXED)||(drvType == DRIVE_NO_ROOT_DIR))) {
201                        message = "UNKNOWN: Drive is not a fixed drive: " + drive.getAlias() + " (it is a: " + strEx::itos(drvType) + ")";
202                        return NSCAPI::returnUNKNOWN;
203                } else if ( (bFilter)&&( (!bFilterFixed)&&((drvType==DRIVE_FIXED)||(drvType==DRIVE_NO_ROOT_DIR))) ||
204                        ((!bFilterCDROM)&&(drvType==DRIVE_CDROM)) ||
205                        ((!bFilterRemote)&&(drvType==DRIVE_REMOTE)) ||
206                        ((!bFilterRemovable)&&(drvType==DRIVE_REMOVABLE)) ) {
207                        message = "UNKNOWN: Drive does not match the current filter: " + drive.getAlias() + " (it is a: " + strEx::itos(drvType) + ")";
208                        return NSCAPI::returnUNKNOWN;
209                }
210
211                ULARGE_INTEGER freeBytesAvailableToCaller;
212                ULARGE_INTEGER totalNumberOfBytes;
213                ULARGE_INTEGER totalNumberOfFreeBytes;
214                if (!GetDiskFreeSpaceEx(drive.data.c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) {
215                        message = "UNKNOWN: Could not get free space for: " + drive.getAlias() + + " \"" + drive.data + "\" reason: " + strEx::itos(GetLastError());
216                        return NSCAPI::returnUNKNOWN;
217                }
218
219                if (bNSClient) {
220                        if (!message.empty())
221                                message += "&";
222                        message += strEx::itos(totalNumberOfFreeBytes.QuadPart);
223                        message += "&";
224                        message += strEx::itos(totalNumberOfBytes.QuadPart);
225                } else {
226                        checkHolders::PercentageValueType<checkHolders::disk_size_type, checkHolders::disk_size_type> value;
227                        std::string tstr;
228                        value.value = totalNumberOfBytes.QuadPart-totalNumberOfFreeBytes.QuadPart;
229                        value.total = totalNumberOfBytes.QuadPart;
230                        drive.setDefault(tmpObject);
231                        drive.runCheck(value, returnCode, message, perf);
232                }
233        }
234        if (message.empty())
235                message = "OK: All drives within bounds.";
236        else if (!bNSClient)
237                message = NSCHelper::translateReturn(returnCode) + ": " + message;
238        return returnCode;
239}
240
241
242
243NSCAPI::nagiosReturn CheckDisk::CheckFileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) {
244        NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK;
245        std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args);
246        bool bPerfData = true;
247        if (args.empty()) {
248                message = "Missing argument(s).";
249                return NSCAPI::returnUNKNOWN;
250        }
251        PathConatiner tmpObject;
252        std::list<PathConatiner> paths;
253
254        MAP_OPTIONS_BEGIN(args)
255                MAP_OPTIONS_STR_AND("File", tmpObject.data, paths.push_back(tmpObject))
256                MAP_OPTIONS_SHOWALL(tmpObject)
257                MAP_OPTIONS_STR("MaxWarn", tmpObject.warn.max)
258                MAP_OPTIONS_STR("MinWarn", tmpObject.warn.min)
259                MAP_OPTIONS_STR("MaxCrit", tmpObject.crit.max)
260                MAP_OPTIONS_STR("MinCrit", tmpObject.crit.min)
261                MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData)
262                MAP_OPTIONS_SECONDARY_BEGIN(":", p2)
263                else if (p2.first == "File") {
264                        tmpObject.data = p__.second;
265                        tmpObject.alias = p2.second;
266                        paths.push_back(tmpObject);
267                }
268                MAP_OPTIONS_MISSING_EX(p2, message, "Unknown argument: ")
269                MAP_OPTIONS_SECONDARY_END()
270                MAP_OPTIONS_MISSING(message, "Unknown argument: ")
271        MAP_OPTIONS_END()
272
273        for (std::list<PathConatiner>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) {
274                PathConatiner path = (*pit);
275                std::string tstr;
276                std::string sName = path.getAlias();
277                get_size sizeFinder;
278                recursive_scan<get_size>(path.data, sizeFinder);
279                if (sizeFinder.hasError()) {
280                        message = "File not found";
281                        return NSCAPI::returnUNKNOWN;
282                }
283                path.setDefault(tmpObject);
284                path.perfData = bPerfData;
285
286                checkHolders::disk_size_type size = sizeFinder.getSize();
287                path.runCheck(size, returnCode, message, perf);
288        }
289        if (message.empty())
290                message = "OK all file sizes are within bounds.";
291        else
292                message = NSCHelper::translateReturn(returnCode) + ": " + message;
293        return returnCode;
294}
295
296
297struct file_info {
298        file_info() : ullCreationTime(0) {}
299        file_info(const BY_HANDLE_FILE_INFORMATION info, std::string filename_) : filename(filename_), ullCreationTime(0) {
300                ullSize = ((info.nFileSizeHigh * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.nFileSizeLow);
301                ullCreationTime = ((info.ftCreationTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftCreationTime.dwLowDateTime);
302                ullLastAccessTime = ((info.ftLastAccessTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftLastAccessTime.dwLowDateTime);
303                ullLastWriteTime = ((info.ftLastWriteTime.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)info.ftLastWriteTime.dwLowDateTime);
304        };
305
306        unsigned long long ullSize;
307        unsigned long long ullCreationTime;
308        unsigned long long ullLastAccessTime;
309        unsigned long long ullLastWriteTime;
310        unsigned long long ullNow;
311        std::string filename;
312
313        std::string render(std::string syntax) {
314                strEx::replace(syntax, "%filename%", filename);
315                strEx::replace(syntax, "%creation%", strEx::format_filetime(ullCreationTime, DATE_FORMAT));
316                strEx::replace(syntax, "%access%", strEx::format_filetime(ullLastAccessTime, DATE_FORMAT));
317                strEx::replace(syntax, "%write%", strEx::format_filetime(ullLastWriteTime, DATE_FORMAT));
318                strEx::replace(syntax, "%size%", strEx::itos_as_BKMG(ullSize));
319                return syntax;
320        }
321
322};
323
324struct file_filter {
325        filters::filter_all_numeric<unsigned long long, checkHolders::disk_size_handler<checkHolders::disk_size_type> > fileSize;
326        filters::filter_all_times fileCreation;
327        filters::filter_all_times fileAccessed;
328        filters::filter_all_times fileWritten;
329        static const __int64 MSECS_TO_100NS = 10000;
330
331        inline bool hasFilter() {
332                return fileSize.hasFilter() || fileCreation.hasFilter() ||
333                        fileAccessed.hasFilter() || fileWritten.hasFilter();
334        }
335        bool matchFilter(const file_info &value) const {
336                if ((fileSize.hasFilter())&&(fileSize.matchFilter(value.ullSize)))
337                        return true;
338                else if ((fileCreation.hasFilter())&&(fileCreation.matchFilter((value.ullNow-value.ullCreationTime)/MSECS_TO_100NS)))
339                        return true;
340                else if ((fileAccessed.hasFilter())&&(fileAccessed.matchFilter((value.ullNow-value.ullLastAccessTime)/MSECS_TO_100NS)))
341                        return true;
342                else if ((fileWritten.hasFilter())&&(fileWritten.matchFilter((value.ullNow-value.ullLastWriteTime)/MSECS_TO_100NS)))
343                        return true;
344                return false;
345        }
346};
347
348
349struct find_first_file_info : public baseFinderFunction
350{
351        file_info info;
352        bool error;
353//      std::string message;
354        find_first_file_info() : error(false) {}
355        result_type operator()(argument_type ffd) {
356                if ((ffd.wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
357                        return true;
358                BY_HANDLE_FILE_INFORMATION _info;
359
360                HANDLE hFile = CreateFile((ffd.path + "\\" + ffd.wfd.cFileName).c_str(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
361                        0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
362                if (hFile == INVALID_HANDLE_VALUE) {
363                        setError("Could not open file: " + ffd.path + "\\" + ffd.wfd.cFileName + ": " + strEx::itos(GetLastError()));
364                        return false;
365                }
366                GetFileInformationByHandle(hFile, &_info);
367                CloseHandle(hFile);
368                info = file_info(_info, ffd.wfd.cFileName);
369                return false;
370        }
371        inline const bool hasError() const {
372                return error;
373        }
374        inline void setError(std::string) {
375                error = true;
376        }
377};
378
379struct file_filter_function : public baseFinderFunction
380{
381        std::list<file_filter> filter_chain;
382        bool bFilterAll;
383        bool bFilterIn;
384        bool error;
385        std::string message;
386        std::string syntax;
387        unsigned long long now;
388        unsigned int hit_count;
389
390        file_filter_function() : hit_count(0), error(false), bFilterIn(true), bFilterAll(true) {}
391        result_type operator()(argument_type ffd) {
392                if ((ffd.wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
393                        return true;
394                BY_HANDLE_FILE_INFORMATION _info;
395
396                HANDLE hFile = CreateFile((ffd.path + "\\" + ffd.wfd.cFileName).c_str(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
397                        0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
398                if (hFile == INVALID_HANDLE_VALUE) {
399                        setError("Could not open file: " + ffd.path + "\\" + ffd.wfd.cFileName + ": " + strEx::itos(GetLastError()));
400                }
401                GetFileInformationByHandle(hFile, &_info);
402                CloseHandle(hFile);
403                file_info info(_info, ffd.wfd.cFileName);
404                info.ullNow = now;
405
406                for (std::list<file_filter>::const_iterator cit3 = filter_chain.begin(); cit3 != filter_chain.end(); ++cit3 ) {
407                        bool bMatch = bFilterAll;
408                        bool bTmpMatched = (*cit3).matchFilter(info);
409                        if (bFilterAll) {
410                                if (!bTmpMatched) {
411                                        bMatch = false;
412                                        break;
413                                }
414                        } else {
415                                if (bTmpMatched) {
416                                        bMatch = true;
417                                        break;
418                                }
419                        }
420                        if ((bFilterIn&&bMatch)||(!bFilterIn&&!bMatch)) {
421                                strEx::append_list(message, info.render(syntax));
422                                hit_count++;
423                        }
424                }
425                return true;
426        }
427        inline const bool hasError() const {
428                return error;
429        }
430        inline void setError(std::string) {
431                error = true;
432        }
433};
434
435NSCAPI::nagiosReturn CheckDisk::getFileAge(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) {
436        NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK;
437        std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args);
438        typedef checkHolders::CheckConatiner<checkHolders::MaxMinBoundsUInteger> CheckFileConatiner;
439        if (stl_args.empty()) {
440                message = "Missing argument(s).";
441                return NSCAPI::returnUNKNOWN;
442        }
443        std::string dstr = "%#c";
444        std::string path;
445        find_first_file_info finder;
446        MAP_OPTIONS_BEGIN(stl_args)
447                MAP_OPTIONS_STR("path", path)
448                MAP_OPTIONS_FALLBACK(dstr)
449        MAP_OPTIONS_END()
450
451        if (path.empty()) {
452                message = "ERROR: no file specified.";
453                return NSCAPI::returnUNKNOWN;
454        }
455
456        recursive_scan<find_first_file_info>(path, finder);
457        if (finder.hasError()) {
458                message = "File not found";
459                return NSCAPI::returnUNKNOWN;
460        }
461        FILETIME now_;
462        GetSystemTimeAsFileTime(&now_);
463        unsigned long long now = ((now_.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now_.dwLowDateTime);
464        time_t value = (now-finder.info.ullLastWriteTime)/10000000;
465
466        char buf[51];
467        size_t l = strftime(buf, 50, dstr.c_str(), gmtime(&value));
468        if (l <= 0 || l >= 50) {
469                message = "ERROR: could format time.";
470                return NSCAPI::returnUNKNOWN;
471        }
472        buf[l] = 0;
473        message = strEx::itos(value) + "&" + buf;
474        return NSCAPI::returnOK;
475}
476
477
478NSCAPI::nagiosReturn CheckDisk::CheckFile(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) {
479        NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK;
480        std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args);
481        typedef checkHolders::CheckConatiner<checkHolders::MaxMinBoundsUInteger> CheckFileConatiner;
482        if (stl_args.empty()) {
483                message = "Missing argument(s).";
484                return NSCAPI::returnUNKNOWN;
485        }
486        file_filter_function finder;
487        PathConatiner tmpObject;
488        std::list<std::string> paths;
489        unsigned int truncate = 0;
490        CheckFileConatiner query;
491        std::string syntax = "%filename%";
492        bool bPerfData = true;
493
494        try {
495                MAP_OPTIONS_BEGIN(stl_args)
496                        MAP_OPTIONS_NUMERIC_ALL(query, "")
497                        MAP_OPTIONS_STR2INT("truncate", truncate)
498                        MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData)
499                        MAP_OPTIONS_STR("syntax", syntax)
500                        MAP_OPTIONS_PUSH("path", paths)
501                        MAP_OPTIONS_PUSH("file", paths)
502                        MAP_OPTIONS_BOOL_EX("filter", finder.bFilterIn, "in", "out")
503                        MAP_OPTIONS_BOOL_EX("filter", finder.bFilterAll, "all", "any")
504                        MAP_OPTIONS_PUSH_WTYPE(file_filter, "filter-size", fileSize, finder.filter_chain)
505                        MAP_OPTIONS_PUSH_WTYPE(file_filter, "filter-creation", fileCreation, finder.filter_chain)
506                        MAP_OPTIONS_PUSH_WTYPE(file_filter, "filter-written", fileWritten, finder.filter_chain)
507                        MAP_OPTIONS_PUSH_WTYPE(file_filter, "filter-accessed", fileAccessed, finder.filter_chain)
508                        MAP_OPTIONS_MISSING(message, "Unknown argument: ")
509                MAP_OPTIONS_END()
510        } catch (filters::parse_exception e) {
511                message = e.getMessage();
512                return NSCAPI::returnUNKNOWN;
513        } catch (filters::filter_exception e) {
514                message = e.getMessage();
515                return NSCAPI::returnUNKNOWN;
516        }
517        FILETIME now;
518        GetSystemTimeAsFileTime(&now);
519        finder.now = ((now.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now.dwLowDateTime);
520        finder.syntax = syntax;
521        for (std::list<std::string>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) {
522                recursive_scan<file_filter_function>((*pit), finder);
523                if (finder.hasError()) {
524                        message = "File not found: " + (*pit);
525                        return NSCAPI::returnUNKNOWN;
526                }
527        }
528        message = finder.message;
529        if (finder.error)
530                return NSCAPI::returnUNKNOWN;
531        query.runCheck(finder.hit_count, returnCode, message, perf);
532        if ((truncate > 0) && (message.length() > (truncate-4)))
533                message = message.substr(0, truncate-4) + "...";
534        if (message.empty())
535                message = "CheckFile ok";
536        return returnCode;
537}
538
539NSCAPI::nagiosReturn CheckDisk::handleCommand(const strEx::blindstr command, const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) {
540        if (command == "CheckFileSize") {
541                return CheckFileSize(argLen, char_args, msg, perf);
542        } else if (command == "CheckDriveSize") {
543                return CheckDriveSize(argLen, char_args, msg, perf);
544        } else if (command == "CheckFile") {
545                return CheckFile(argLen, char_args, msg, perf);
546        } else if (command == "getFileAge") {
547                return getFileAge(argLen, char_args, msg, perf);
548        }       
549        return NSCAPI::returnIgnored;
550}
551
552
553NSC_WRAPPERS_MAIN_DEF(gCheckDisk);
554NSC_WRAPPERS_IGNORE_MSG_DEF();
555NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckDisk);
Note: See TracBrowser for help on using the repository browser.