mirror of https://github.com/Icinga/icinga2.git
Add some failsafes to the windows plugins
This commit is contained in:
parent
667b62cc3c
commit
377f66c403
|
@ -263,8 +263,8 @@ int printOutput(printInfoStruct& printInfo, vector<drive>& vDrives)
|
||||||
int check_drives(vector<drive>& vDrives)
|
int check_drives(vector<drive>& vDrives)
|
||||||
{
|
{
|
||||||
DWORD dwResult, dwSize = 0, dwVolumePathNamesLen = MAX_PATH + 1;
|
DWORD dwResult, dwSize = 0, dwVolumePathNamesLen = MAX_PATH + 1;
|
||||||
wchar_t szLogicalDrives[1024], szVolumeName[MAX_PATH], *szVolumePathNames;
|
wchar_t szLogicalDrives[1024], szVolumeName[MAX_PATH], *szVolumePathNames = NULL;
|
||||||
HANDLE hVolume;
|
HANDLE hVolume = NULL;
|
||||||
wstring wsLogicalDrives;
|
wstring wsLogicalDrives;
|
||||||
size_t volumeNameEnd = 0;
|
size_t volumeNameEnd = 0;
|
||||||
|
|
||||||
|
@ -331,7 +331,8 @@ int check_drives(vector<drive>& vDrives)
|
||||||
}
|
}
|
||||||
|
|
||||||
FindVolumeClose(hVolume);
|
FindVolumeClose(hVolume);
|
||||||
delete[] reinterpret_cast<wchar_t*>(szVolumePathNames);
|
if (szVolumePathNames)
|
||||||
|
delete[] reinterpret_cast<wchar_t*>(szVolumePathNames);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
die:
|
die:
|
||||||
|
|
|
@ -199,7 +199,7 @@ int printOutput(printInfoStruct& printInfo)
|
||||||
|
|
||||||
int check_load(printInfoStruct& printInfo)
|
int check_load(printInfoStruct& printInfo)
|
||||||
{
|
{
|
||||||
PDH_HQUERY phQuery;
|
PDH_HQUERY phQuery = NULL;
|
||||||
PDH_HCOUNTER phCounter;
|
PDH_HCOUNTER phCounter;
|
||||||
DWORD dwBufferSize = 0;
|
DWORD dwBufferSize = 0;
|
||||||
DWORD CounterType;
|
DWORD CounterType;
|
||||||
|
|
|
@ -289,9 +289,12 @@ int check_network(vector <nInterface>& vInterfaces)
|
||||||
if (debug)
|
if (debug)
|
||||||
wcout << L"Finished collection. Cleaning up and returning" << endl;
|
wcout << L"Finished collection. Cleaning up and returning" << endl;
|
||||||
|
|
||||||
PdhCloseQuery(phQuery);
|
if (phQuery)
|
||||||
delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesIn);
|
PdhCloseQuery(phQuery);
|
||||||
delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesOut);
|
if (pDisplayValuesIn)
|
||||||
|
delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesIn);
|
||||||
|
if (pDisplayValuesOut)
|
||||||
|
delete reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(pDisplayValuesOut);
|
||||||
return -1;
|
return -1;
|
||||||
die:
|
die:
|
||||||
die(err);
|
die(err);
|
||||||
|
|
|
@ -351,15 +351,17 @@ int check_ping4(const printInfoStruct& pi, response& response)
|
||||||
if (debug)
|
if (debug)
|
||||||
wcout << L"All pings sent. Cleaning up and returning" << endl;
|
wcout << L"All pings sent. Cleaning up and returning" << endl;
|
||||||
|
|
||||||
IcmpCloseHandle(hIcmp);
|
if (hIcmp)
|
||||||
delete reinterpret_cast<VOID *>(repBuf);
|
IcmpCloseHandle(hIcmp);
|
||||||
|
if (repBuf)
|
||||||
|
delete reinterpret_cast<VOID *>(repBuf);
|
||||||
|
|
||||||
response.avg = ((double)rtt / pi.num);
|
response.avg = ((double)rtt / pi.num);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
die:
|
die:
|
||||||
die(GetLastError());
|
die();
|
||||||
if (hIcmp)
|
if (hIcmp)
|
||||||
IcmpCloseHandle(hIcmp);
|
IcmpCloseHandle(hIcmp);
|
||||||
if (repBuf)
|
if (repBuf)
|
||||||
|
@ -375,6 +377,7 @@ int check_ping6(const printInfoStruct& pi, response& response)
|
||||||
IP_OPTION_INFORMATION ipInfo = { 30, 0, 0, 0, NULL };
|
IP_OPTION_INFORMATION ipInfo = { 30, 0, 0, 0, NULL };
|
||||||
DWORD dwRepSize = sizeof(ICMPV6_ECHO_REPLY) + 8;
|
DWORD dwRepSize = sizeof(ICMPV6_ECHO_REPLY) + 8;
|
||||||
LPVOID repBuf = reinterpret_cast<VOID *>(new BYTE[dwRepSize]);
|
LPVOID repBuf = reinterpret_cast<VOID *>(new BYTE[dwRepSize]);
|
||||||
|
HANDLE hIcmp = NULL;
|
||||||
|
|
||||||
LARGE_INTEGER frequency, timer1, timer2;
|
LARGE_INTEGER frequency, timer1, timer2;
|
||||||
int num = pi.num;
|
int num = pi.num;
|
||||||
|
@ -398,7 +401,7 @@ int check_ping6(const printInfoStruct& pi, response& response)
|
||||||
if (debug)
|
if (debug)
|
||||||
wcout << L"Creating Icmp File" << endl;
|
wcout << L"Creating Icmp File" << endl;
|
||||||
|
|
||||||
HANDLE hIcmp = Icmp6CreateFile();
|
hIcmp = Icmp6CreateFile();
|
||||||
if (hIcmp == INVALID_HANDLE_VALUE) {
|
if (hIcmp == INVALID_HANDLE_VALUE) {
|
||||||
goto die;
|
goto die;
|
||||||
}
|
}
|
||||||
|
@ -450,8 +453,10 @@ int check_ping6(const printInfoStruct& pi, response& response)
|
||||||
if (debug)
|
if (debug)
|
||||||
wcout << L"All pings sent. Cleaning up and returning" << endl;
|
wcout << L"All pings sent. Cleaning up and returning" << endl;
|
||||||
|
|
||||||
IcmpCloseHandle(hIcmp);
|
if (hIcmp)
|
||||||
delete reinterpret_cast<VOID *>(repBuf);
|
IcmpCloseHandle(hIcmp);
|
||||||
|
if (repBuf)
|
||||||
|
delete reinterpret_cast<VOID *>(repBuf);
|
||||||
response.avg = ((double)rtt / pi.num);
|
response.avg = ((double)rtt / pi.num);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -208,7 +208,7 @@ int countProcs()
|
||||||
if (debug)
|
if (debug)
|
||||||
wcout << L"Counting all processes" << endl;
|
wcout << L"Counting all processes" << endl;
|
||||||
|
|
||||||
HANDLE hProcessSnap;
|
HANDLE hProcessSnap = NULL;
|
||||||
PROCESSENTRY32 pe32;
|
PROCESSENTRY32 pe32;
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
|
@ -240,7 +240,8 @@ int countProcs()
|
||||||
if (debug)
|
if (debug)
|
||||||
wcout << L"Found " << numProcs << L" processes. Cleaning up udn returning" << endl;
|
wcout << L"Found " << numProcs << L" processes. Cleaning up udn returning" << endl;
|
||||||
|
|
||||||
CloseHandle(hProcessSnap);
|
if (hProcessSnap)
|
||||||
|
CloseHandle(hProcessSnap);
|
||||||
return numProcs;
|
return numProcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ static BOOL debug = FALSE;
|
||||||
struct printInfoStruct
|
struct printInfoStruct
|
||||||
{
|
{
|
||||||
threshold warn, crit;
|
threshold warn, crit;
|
||||||
DWORD tSwap, aSwap;
|
double tSwap, aSwap;
|
||||||
Bunit unit = BunitMB;
|
Bunit unit = BunitMB;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -210,14 +210,16 @@ int printOutput(printInfoStruct& printInfo)
|
||||||
|
|
||||||
int check_swap(printInfoStruct& printInfo)
|
int check_swap(printInfoStruct& printInfo)
|
||||||
{
|
{
|
||||||
_MEMORYSTATUS *pMemBuf = new _MEMORYSTATUS;
|
MEMORYSTATUSEX MemBuf;
|
||||||
|
MemBuf.dwLength = sizeof(MemBuf);
|
||||||
|
|
||||||
GlobalMemoryStatus(pMemBuf);
|
if (!GlobalMemoryStatusEx(&MemBuf)) {
|
||||||
|
die();
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
printInfo.tSwap = round(pMemBuf->dwTotalPageFile / pow(1024.0, printInfo.unit));
|
printInfo.tSwap = round(MemBuf.ullTotalPageFile / pow(1024.0, printInfo.unit));
|
||||||
printInfo.aSwap = round(pMemBuf->dwAvailPageFile / pow(1024.0, printInfo.unit));
|
printInfo.aSwap = round(MemBuf.ullAvailPageFile / pow(1024.0, printInfo.unit));
|
||||||
|
|
||||||
delete pMemBuf;
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
|
@ -130,7 +130,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
||||||
, progName, progName);
|
, progName, progName);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
return 0;
|
return 0;
|
||||||
} if (vm.count("version")) {
|
} if (vm.count("version")) {
|
||||||
cout << "Version: " << VERSION << endl;
|
cout << "Version: " << VERSION << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -190,6 +190,7 @@ int check_update(printInfoStruct& printInfo)
|
||||||
ISearchResult *pResult;
|
ISearchResult *pResult;
|
||||||
IUpdateSession *pSession;
|
IUpdateSession *pSession;
|
||||||
IUpdateSearcher *pSearcher;
|
IUpdateSearcher *pSearcher;
|
||||||
|
BSTR criteria = NULL;
|
||||||
|
|
||||||
HRESULT err;
|
HRESULT err;
|
||||||
if (debug)
|
if (debug)
|
||||||
|
@ -204,7 +205,7 @@ int check_update(printInfoStruct& printInfo)
|
||||||
RebootRequired = 1: Reboot required
|
RebootRequired = 1: Reboot required
|
||||||
*/
|
*/
|
||||||
|
|
||||||
BSTR criteria = SysAllocString(CRITERIA);
|
criteria = SysAllocString(CRITERIA);
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526%28v=vs.85%29.aspx
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526%28v=vs.85%29.aspx
|
||||||
// http://msdn.microsoft.com/en-us/library/ff357803%28v=vs.85%29.aspx
|
// http://msdn.microsoft.com/en-us/library/ff357803%28v=vs.85%29.aspx
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue