# along with this program; if not, write to the Free Software Foundation
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
-if (WIN32)
+if ( WIN32 )
- add_definitions(-DUNICODE -D_UNICODE)
+ add_definitions( -DUNICODE -D_UNICODE )
- add_library(thresholds thresholds)
+ add_library( thresholds thresholds )
set_target_properties (
thresholds PROPERTIES
INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/icinga2
FOLDER Plugins
)
- list(APPEND check_SOURCES
+ list( APPEND check_SOURCES
check_disk.cpp check_load.cpp check_network.cpp check_ping.cpp check_procs.cpp check_service.cpp
- check_swap.cpp check_update.cpp check_uptime.cpp check_users.cpp)
+ check_swap.cpp check_update.cpp check_uptime.cpp check_users.cpp )
- foreach (source ${check_SOURCES})
- string (REGEX REPLACE ".cpp\$" "" check_OUT "${source}")
+ foreach ( source ${check_SOURCES} )
+ string ( REGEX REPLACE ".cpp\$" "" check_OUT "${source}" )
- add_executable (${check_OUT} ${source})
- target_link_libraries(${check_OUT} thresholds Shlwapi.lib ${Boost_PROGRAM_OPTIONS_LIBRARY})
+ add_executable ( ${check_OUT} ${source} )
+ target_link_libraries( ${check_OUT} thresholds Shlwapi.lib ${Boost_PROGRAM_OPTIONS_LIBRARY} )
set_target_properties (
${check_OUT} PROPERTIES
FOLDER Plugins)
endforeach(source)
- target_link_libraries(check_load Pdh.lib)
- target_link_libraries(check_network Pdh.lib)
- target_link_libraries(check_ping Ntdll.lib iphlpapi.lib Ws2_32.lib )
- target_link_libraries(check_procs Pdh.lib)
- target_link_libraries(check_swap Pdh.lib)
- target_link_libraries(check_uptime ${Boost_SYSTEM_LIBRARY})
- target_link_libraries(check_users wtsapi32.lib)
+ target_link_libraries( check_load Pdh.lib )
+ target_link_libraries( check_network Pdh.lib )
+ target_link_libraries( check_ping Ntdll.lib iphlpapi.lib Ws2_32.lib )
+ target_link_libraries( check_procs Pdh.lib )
+ target_link_libraries( check_uptime ${Boost_SYSTEM_LIBRARY} )
+ target_link_libraries( check_users wtsapi32.lib )
install (
TARGETS check_disk check_load check_network check_procs check_ping check_service check_swap check_update check_uptime check_users
- RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR})
+ RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR} )
endif()
\ No newline at end of file
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include <Shlwapi.h>
-#include <Pdh.h>
#include <iostream>
+#include <WinBase.h>
#include "thresholds.h"
struct printInfoStruct
{
threshold warn, crit;
- double swap;
+ DWORD tSwap, aSwap;
};
static int parseArguments(int, wchar_t **, po::variables_map&, printInfoStruct&);
cout << desc;
wprintf(
L"\nIt will then output a string looking something like this:\n\n"
- L"\tSWAP WARNING 23.8304%%|swap=23.8304%%;19.5;30;0;100\n\n"
+ L"\tSWAP WARNING - 20%% free | swap=2000B;3000;500;0;10000\n\n"
L"\"SWAP\" being the type of the check, \"WARNING\" the returned status\n"
L"and \"23.8304%%\" is the returned value.\n"
L"The performance data is found behind the \"|\", in order:\n"
wcout << L"Constructing output string" << endl;
state state = OK;
+ double fswap = (printInfo.aSwap / printInfo.tSwap) * 100.0;
- if (printInfo.warn.rend(printInfo.swap))
+ if (!printInfo.warn.rend(printInfo.aSwap, printInfo.tSwap))
state = WARNING;
- if (printInfo.crit.rend(printInfo.swap))
+ if (!printInfo.crit.rend(printInfo.aSwap, printInfo.tSwap))
state = CRITICAL;
switch (state) {
case OK:
- wcout << L"SWAP OK " << printInfo.swap << L"% | swap=" << printInfo.swap << L"%;"
- << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;100" << endl;
+ wcout << L"SWAP OK - " << fswap << L"% free | swap=" << printInfo.aSwap << L"B;"
+ << printInfo.warn.pString(printInfo.tSwap) << L";" << printInfo.crit.pString(printInfo.tSwap)
+ << L";0;" << printInfo.tSwap << endl;
break;
case WARNING:
- wcout << L"SWAP WARNING " << printInfo.swap << L"% | swap=" << printInfo.swap << L"%;"
- << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;100" << endl;
+ wcout << L"SWAP WARNING - " << fswap << L"% free | swap=" << printInfo.aSwap << L"B;"
+ << printInfo.warn.pString(printInfo.tSwap) << L";" << printInfo.crit.pString(printInfo.tSwap)
+ << L";0;" << printInfo.tSwap << endl;
break;
case CRITICAL:
- wcout << L"SWAP CRITICAL " << printInfo.swap << L"% | swap=" << printInfo.swap << L"%;"
- << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;100" << endl;
+ wcout << L"SWAP CRITICAL - " << fswap << L"% free | swap=" << printInfo.aSwap << L"B;"
+ << printInfo.warn.pString(printInfo.tSwap) << L";" << printInfo.crit.pString(printInfo.tSwap)
+ << L";0;" << printInfo.tSwap << endl;
break;
}
int check_swap(printInfoStruct& printInfo)
{
- PDH_HQUERY phQuery;
- PDH_HCOUNTER phCounter;
- DWORD dwBufferSize = 0;
- DWORD CounterType;
- PDH_FMT_COUNTERVALUE DisplayValue;
- PDH_STATUS err;
+ _MEMORYSTATUS *pMemBuf = new _MEMORYSTATUS;
- LPCWSTR path = L"\\Paging File(*)\\% Usage";
+ GlobalMemoryStatus(pMemBuf);
- if (debug)
- wcout << L"Opening querry handle" << endl;
-
- err = PdhOpenQuery(NULL, NULL, &phQuery);
- if (!SUCCEEDED(err))
- goto die;
-
- if (debug)
- wcout << L"Adding counter" << endl;
-
- err = PdhAddEnglishCounter(phQuery, path, NULL, &phCounter);
- if (!SUCCEEDED(err))
- goto die;
-
- if (debug)
- wcout << L"Collecting querry data" << endl;
-
- err = PdhCollectQueryData(phQuery);
- if (!SUCCEEDED(err))
- goto die;
-
- if (debug)
- wcout << L"Formatting counter data" << endl;
+ printInfo.tSwap = pMemBuf->dwTotalPageFile;
+ printInfo.aSwap = pMemBuf->dwAvailPageFile;
- err = PdhGetFormattedCounterValue(phCounter, PDH_FMT_DOUBLE, &CounterType, &DisplayValue);
- if (SUCCEEDED(err)) {
- printInfo.swap = DisplayValue.doubleValue;
- PdhCloseQuery(phQuery);
- return -1;
- }
+ delete pMemBuf;
-die:
- if (phQuery)
- PdhCloseQuery(phQuery);
- die(err);
- return 3;
+ return -1;
}
\ No newline at end of file