source: nscp/trunk/modules/CheckDisk/CheckDisk.cpp @ 7b51081

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

Getting ready for the 0.2.7 release, a few minor fixes here and there...

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