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