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