mirror of https://github.com/Icinga/icinga2.git
parent
3d52acfe5d
commit
616716dc55
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "thresholds.h"
|
||||
|
||||
#include "boost\program_options.hpp"
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
#define VERSION 1.0
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "thresholds.h"
|
||||
|
||||
#include "boost\program_options.hpp"
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
#define VERSION 1.0
|
||||
|
||||
|
@ -41,6 +41,7 @@ struct printInfoStruct
|
|||
static int parseArguments(int, wchar_t **, po::variables_map&, printInfoStruct&);
|
||||
static int printOutput(printInfoStruct&);
|
||||
static int check_load(printInfoStruct&);
|
||||
static void die(DWORD err = 0);
|
||||
|
||||
int wmain(int argc, wchar_t **argv)
|
||||
{
|
||||
|
@ -196,32 +197,49 @@ int check_load(printInfoStruct& printInfo)
|
|||
DWORD dwBufferSize = 0;
|
||||
DWORD CounterType;
|
||||
PDH_FMT_COUNTERVALUE DisplayValue;
|
||||
PDH_STATUS err;
|
||||
|
||||
LPCWSTR path = L"\\Processor(_Total)\\% Idle Time";
|
||||
|
||||
if (PdhOpenQuery(NULL, NULL, &phQuery) != ERROR_SUCCESS)
|
||||
goto cleanup;
|
||||
err = PdhOpenQuery(NULL, NULL, &phQuery);
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
if (PdhAddEnglishCounter(phQuery, path, NULL, &phCounter) != ERROR_SUCCESS)
|
||||
goto cleanup;
|
||||
err = PdhAddEnglishCounter(phQuery, path, NULL, &phCounter);
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
if (PdhCollectQueryData(phQuery) != ERROR_SUCCESS)
|
||||
goto cleanup;
|
||||
err = PdhCollectQueryData(phQuery);
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
Sleep(1000);
|
||||
|
||||
if (PdhCollectQueryData(phQuery) != ERROR_SUCCESS)
|
||||
goto cleanup;
|
||||
err = PdhCollectQueryData(phQuery);
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
if (PdhGetFormattedCounterValue(phCounter, PDH_FMT_DOUBLE, &CounterType, &DisplayValue) == ERROR_SUCCESS) {
|
||||
err = PdhGetFormattedCounterValue(phCounter, PDH_FMT_DOUBLE, &CounterType, &DisplayValue);
|
||||
if (SUCCEEDED(err)) {
|
||||
if (DisplayValue.CStatus == PDH_CSTATUS_VALID_DATA)
|
||||
printInfo.load = 100.0 - DisplayValue.doubleValue;
|
||||
PdhCloseQuery(phQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
die:
|
||||
die();
|
||||
if (phQuery)
|
||||
PdhCloseQuery(phQuery);
|
||||
return 3;
|
||||
}
|
||||
|
||||
void die(DWORD err)
|
||||
{
|
||||
if (!err)
|
||||
err = GetLastError();
|
||||
LPWSTR mBuf = NULL;
|
||||
size_t mS = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&mBuf, 0, NULL);
|
||||
wcout << mBuf << endl;
|
||||
}
|
|
@ -45,7 +45,7 @@ struct printInfoStruct
|
|||
threshold warn, crit;
|
||||
};
|
||||
|
||||
static void die(const DWORD err);
|
||||
static void die(DWORD err = 0);
|
||||
static int parseArguments(int, TCHAR **, po::variables_map&, printInfoStruct&);
|
||||
static int printOutput(printInfoStruct&, const vector<nInterface>&);
|
||||
static int check_network(vector<nInterface>&);
|
||||
|
@ -217,45 +217,45 @@ int check_network(vector <nInterface>& vInterfaces)
|
|||
PDH_STATUS err;
|
||||
|
||||
err = PdhOpenQuery(NULL, NULL, &phQuery);
|
||||
if (err != ERROR_SUCCESS)
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
err = PdhAddEnglishCounter(phQuery, perfIn, NULL, &phCounterIn);
|
||||
if (err != ERROR_SUCCESS)
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
err = PdhAddEnglishCounter(phQuery, perfOut, NULL, &phCounterOut);
|
||||
if (err != ERROR_SUCCESS)
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
err = PdhCollectQueryData(phQuery);
|
||||
if (err != ERROR_SUCCESS)
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
Sleep(1000);
|
||||
|
||||
err = PdhCollectQueryData(phQuery);
|
||||
if (err != ERROR_SUCCESS)
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
err = PdhGetFormattedCounterArray(phCounterIn, PDH_FMT_LONG, &dwBufferSizeIn, &dwItemCount, pDisplayValuesIn);
|
||||
if (err == PDH_MORE_DATA || err == ERROR_SUCCESS)
|
||||
if (err == PDH_MORE_DATA || SUCCEEDED(err))
|
||||
pDisplayValuesIn = new PDH_FMT_COUNTERVALUE_ITEM[dwItemCount*dwBufferSizeIn];
|
||||
else
|
||||
goto die;
|
||||
|
||||
err = PdhGetFormattedCounterArray(phCounterOut, PDH_FMT_LONG, &dwBufferSizeOut, &dwItemCount, pDisplayValuesOut);
|
||||
if (err == PDH_MORE_DATA || err == ERROR_SUCCESS)
|
||||
if (err == PDH_MORE_DATA || SUCCEEDED(err))
|
||||
pDisplayValuesOut = new PDH_FMT_COUNTERVALUE_ITEM[dwItemCount*dwBufferSizeOut];
|
||||
else
|
||||
goto die;
|
||||
|
||||
err = PdhGetFormattedCounterArray(phCounterIn, PDH_FMT_LONG, &dwBufferSizeIn, &dwItemCount, pDisplayValuesIn);
|
||||
if (err != ERROR_SUCCESS)
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
err = PdhGetFormattedCounterArray(phCounterOut, PDH_FMT_LONG, &dwBufferSizeOut, &dwItemCount, pDisplayValuesOut);
|
||||
if (err != ERROR_SUCCESS)
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
for (DWORD i = 0; i < dwItemCount; i++) {
|
||||
|
@ -279,7 +279,7 @@ die:
|
|||
return 3;
|
||||
}
|
||||
|
||||
void die(DWORD err = 0)
|
||||
void die(DWORD err)
|
||||
{
|
||||
if (!err)
|
||||
err = GetLastError();
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include "thresholds.h"
|
||||
|
||||
#include "boost\program_options.hpp"
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
#define VERSION 1.0
|
||||
|
||||
|
@ -40,6 +40,7 @@ struct printInfoStruct
|
|||
static int parseArguments(int, wchar_t **, po::variables_map&, printInfoStruct&);
|
||||
static int printOutput(printInfoStruct&);
|
||||
static int check_swap(printInfoStruct&);
|
||||
static void die(DWORD err = 0);
|
||||
|
||||
int wmain(int argc, wchar_t **argv)
|
||||
{
|
||||
|
@ -194,26 +195,42 @@ int check_swap(printInfoStruct& printInfo)
|
|||
DWORD dwBufferSize = 0;
|
||||
DWORD CounterType;
|
||||
PDH_FMT_COUNTERVALUE DisplayValue;
|
||||
PDH_STATUS err;
|
||||
|
||||
LPCWSTR path = L"\\Paging File(*)\\% Usage";
|
||||
|
||||
if (PdhOpenQuery(NULL, NULL, &phQuery) != ERROR_SUCCESS)
|
||||
goto cleanup;
|
||||
err = PdhOpenQuery(NULL, NULL, &phQuery);
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
if (PdhAddEnglishCounter(phQuery, path, NULL, &phCounter) != ERROR_SUCCESS)
|
||||
goto cleanup;
|
||||
err = PdhAddEnglishCounter(phQuery, path, NULL, &phCounter);
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
if (PdhCollectQueryData(phQuery) != ERROR_SUCCESS)
|
||||
goto cleanup;
|
||||
err = PdhCollectQueryData(phQuery);
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
|
||||
if (PdhGetFormattedCounterValue(phCounter, PDH_FMT_DOUBLE, &CounterType, &DisplayValue) == ERROR_SUCCESS) {
|
||||
err = PdhGetFormattedCounterValue(phCounter, PDH_FMT_DOUBLE, &CounterType, &DisplayValue);
|
||||
if (SUCCEEDED(err)) {
|
||||
printInfo.swap = DisplayValue.doubleValue;
|
||||
PdhCloseQuery(phQuery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
die:
|
||||
if (phQuery)
|
||||
PdhCloseQuery(phQuery);
|
||||
die(err);
|
||||
return 3;
|
||||
}
|
||||
|
||||
void die(DWORD err)
|
||||
{
|
||||
if (!err)
|
||||
err = GetLastError();
|
||||
LPWSTR mBuf = NULL;
|
||||
size_t mS = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&mBuf, 0, NULL);
|
||||
wcout << mBuf << endl;
|
||||
}
|
|
@ -45,6 +45,7 @@ struct printInfoStruct
|
|||
static int parseArguments(int, wchar_t **, po::variables_map&, printInfoStruct&);
|
||||
static int printOutput(const printInfoStruct&);
|
||||
static int check_update(printInfoStruct&);
|
||||
static void die(DWORD err = 0);
|
||||
|
||||
int main(int argc, wchar_t **argv)
|
||||
{
|
||||
|
@ -186,10 +187,11 @@ int check_update(printInfoStruct& printInfo)
|
|||
IUpdateSession *pSession;
|
||||
IUpdateSearcher *pSearcher;
|
||||
|
||||
HRESULT err;
|
||||
|
||||
CoCreateInstance(CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSession, (LPVOID*)&pSession);
|
||||
pSession->CreateUpdateSearcher(&pSearcher);
|
||||
|
||||
|
||||
/*
|
||||
IsInstalled = 0: All updates, including languagepacks and features
|
||||
BrowseOnly = 0: No features or languagepacks, security and unnamed
|
||||
|
@ -201,7 +203,8 @@ int check_update(printInfoStruct& printInfo)
|
|||
// 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
|
||||
|
||||
if (pSearcher->Search(criteria, &pResult) != S_OK)
|
||||
err = pSearcher->Search(criteria, &pResult);
|
||||
if (!SUCCEEDED(err))
|
||||
goto die;
|
||||
SysFreeString(criteria);
|
||||
|
||||
|
@ -241,5 +244,16 @@ int check_update(printInfoStruct& printInfo)
|
|||
die:
|
||||
if (criteria)
|
||||
SysFreeString(criteria);
|
||||
die(err);
|
||||
return 3;
|
||||
}
|
||||
|
||||
void die(DWORD err)
|
||||
{
|
||||
if (!err)
|
||||
err = GetLastError();
|
||||
LPWSTR mBuf = NULL;
|
||||
size_t mS = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&mBuf, 0, NULL);
|
||||
wcout << mBuf << endl;
|
||||
}
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
#include "thresholds.h"
|
||||
|
||||
#include "boost\chrono.hpp"
|
||||
#include "boost\program_options.hpp"
|
||||
#include "boost/chrono.hpp"
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
#define VERSION 1.0
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "thresholds.h"
|
||||
|
||||
#include "boost\program_options.hpp"
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
#define VERSION 1.0
|
||||
|
||||
|
@ -35,7 +35,7 @@ using std::cout; using std::wstring;
|
|||
struct printInfoStruct
|
||||
{
|
||||
threshold warn, crit;
|
||||
int users;
|
||||
double users;
|
||||
};
|
||||
|
||||
static int parseArguments(int, wchar_t **, po::variables_map&, printInfoStruct&);
|
||||
|
@ -190,13 +190,15 @@ int printOutput(printInfoStruct& printInfo)
|
|||
|
||||
int check_users(printInfoStruct& printInfo)
|
||||
{
|
||||
int users = 0;
|
||||
WTS_SESSION_INFOW *pSessionInfo;
|
||||
double users = 0;
|
||||
WTS_SESSION_INFOW *pSessionInfo = NULL;
|
||||
DWORD count;
|
||||
DWORD index;
|
||||
|
||||
if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &count)) {
|
||||
wcout << L"Failed to enumerate terminal sessions" << endl;
|
||||
if (pSessionInfo)
|
||||
WTSFreeMemory(pSessionInfo);
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
@ -223,5 +225,4 @@ int check_users(printInfoStruct& printInfo)
|
|||
WTSFreeMemory(pSessionInfo);
|
||||
printInfo.users = users;
|
||||
return -1;
|
||||
|
||||
}
|
Loading…
Reference in New Issue