| 1 | /**************************************************************************
|
|---|
| 2 | * Copyright (C) 2004-2007 by Michael Medin <michael@medin.name> *
|
|---|
| 3 | * *
|
|---|
| 4 | * This code is part of NSClient++ - http://trac.nakednuns.org/nscp *
|
|---|
| 5 | * *
|
|---|
| 6 | * This program is free software; you can redistribute it and/or modify *
|
|---|
| 7 | * it under the terms of the GNU General Public License as published by *
|
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or *
|
|---|
| 9 | * (at your option) any later version. *
|
|---|
| 10 | * *
|
|---|
| 11 | * This program is distributed in the hope that it will be useful, *
|
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|---|
| 14 | * GNU General Public License for more details. *
|
|---|
| 15 | * *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License *
|
|---|
| 17 | * along with this program; if not, write to the *
|
|---|
| 18 | * Free Software Foundation, Inc., *
|
|---|
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|---|
| 20 | ***************************************************************************/
|
|---|
| 21 | #include "stdafx.h"
|
|---|
| 22 | #include "DebugLogMetrics.h"
|
|---|
| 23 | #include <strEx.h>
|
|---|
| 24 | #include <time.h>
|
|---|
| 25 | #include <config.h>
|
|---|
| 26 | #include <msvc_wrappers.h>
|
|---|
| 27 | #include <Psapi.h>
|
|---|
| 28 |
|
|---|
| 29 | DebugLogMetrics gDebugLogMetrics;
|
|---|
| 30 |
|
|---|
| 31 | BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
|---|
| 32 | {
|
|---|
| 33 | NSCModuleWrapper::wrapDllMain(hModule, ul_reason_for_call);
|
|---|
| 34 | return TRUE;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | DebugLogMetrics::DebugLogMetrics() : pdhThread(_T("debugThread")) {}
|
|---|
| 38 | DebugLogMetrics::~DebugLogMetrics() {}
|
|---|
| 39 |
|
|---|
| 40 | bool DebugLogMetrics::loadModule(NSCAPI::moduleLoadMode mode) {
|
|---|
| 41 | // timeout = SETTINGS_GET_INT() NSCModuleHelper::getSettingsInt(EXTSCRIPT_SECTION_TITLE, EXTSCRIPT_SETTINGS_TIMEOUT ,EXTSCRIPT_SETTINGS_TIMEOUT_DEFAULT);
|
|---|
| 42 | // scriptDirectory_ = NSCModuleHelper::getSettingsString(EXTSCRIPT_SECTION_TITLE, EXTSCRIPT_SETTINGS_SCRIPTDIR ,EXTSCRIPT_SETTINGS_SCRIPTDIR_DEFAULT);
|
|---|
| 43 | root_ = NSCModuleHelper::getBasePath();
|
|---|
| 44 | pdhThread.createThread(_T("NSClient++"));
|
|---|
| 45 | return true;
|
|---|
| 46 | }
|
|---|
| 47 | bool DebugLogMetrics::unloadModule() {
|
|---|
| 48 | if (!pdhThread.exitThread(20000)) {
|
|---|
| 49 | std::wcout << _T("MAJOR ERROR: Could not unload thread...") << std::endl;
|
|---|
| 50 | NSC_LOG_ERROR(_T("Could not exit the thread, memory leak and potential corruption may be the result..."));
|
|---|
| 51 | }
|
|---|
| 52 | return true;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | bool DebugLogMetrics::hasCommandHandler() {
|
|---|
| 57 | return true;
|
|---|
| 58 | }
|
|---|
| 59 | bool DebugLogMetrics::hasMessageHandler() {
|
|---|
| 60 | return false;
|
|---|
| 61 | }
|
|---|
| 62 | /*
|
|---|
| 63 | void getMetricsForPid(DWORD pid) {
|
|---|
| 64 | HANDLE hProcModule = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid );
|
|---|
| 65 | if( !hProcModule ) {
|
|---|
| 66 | NSC_LOG_ERROR_STD(_T("Failed to open process: ") + error::lookup::last_error());
|
|---|
| 67 | return;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | PROCESS_MEMORY_COUNTERS pmc;
|
|---|
| 71 | if (!GetProcessMemoryInfo( hProcModule, &pmc, sizeof(pmc))) {
|
|---|
| 72 | NSC_LOG_ERROR_STD(_T("Failed to get process memory info: ") + error::lookup::last_error());
|
|---|
| 73 | CloseHandle(hProcModule);
|
|---|
| 74 | return;
|
|---|
| 75 | }
|
|---|
| 76 | NSC_LOG_MESSAGE_STD(_T("Memory: ") + strEx::itos(pmc.WorkingSetSize));
|
|---|
| 77 |
|
|---|
| 78 | CloseHandle( hProcModule );
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | void getMetricsForName(std::wstring name) {
|
|---|
| 82 |
|
|---|
| 83 | }
|
|---|
| 84 | */
|
|---|
| 85 |
|
|---|
| 86 | NSCAPI::nagiosReturn DebugLogMetrics::handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) {
|
|---|
| 87 | if (pdhThread.hasActiveThread())
|
|---|
| 88 | pdhThread.getThread()->store(command.c_str());
|
|---|
| 89 | //getMetricsForPid(GetCurrentProcessId());
|
|---|
| 90 | return NSCAPI::returnIgnored;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 | NSC_WRAPPERS_MAIN_DEF(gDebugLogMetrics);
|
|---|
| 95 | NSC_WRAPPERS_IGNORE_MSG_DEF();
|
|---|
| 96 | NSC_WRAPPERS_HANDLE_CMD_DEF(gDebugLogMetrics);
|
|---|
| 97 | NSC_WRAPPERS_HANDLE_CONFIGURATION(gDebugLogMetrics);
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | MODULE_SETTINGS_START(DebugLogMetrics, _T("NRPE Listener configuration"), _T("..."))
|
|---|
| 101 |
|
|---|
| 102 | PAGE(_T("NRPE Listsner configuration"))
|
|---|
| 103 |
|
|---|
| 104 | ITEM_EDIT_TEXT(_T("port"), _T("This is the port the DebugLogMetrics.dll will listen to."))
|
|---|
| 105 | ITEM_MAP_TO(_T("basic_ini_text_mapper"))
|
|---|
| 106 | OPTION(_T("section"), _T("NRPE"))
|
|---|
| 107 | OPTION(_T("key"), _T("port"))
|
|---|
| 108 | OPTION(_T("default"), _T("5666"))
|
|---|
| 109 | ITEM_END()
|
|---|
| 110 |
|
|---|
| 111 | ITEM_CHECK_BOOL(_T("allow_arguments"), _T("This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed."))
|
|---|
| 112 | ITEM_MAP_TO(_T("basic_ini_bool_mapper"))
|
|---|
| 113 | OPTION(_T("section"), _T("NRPE"))
|
|---|
| 114 | OPTION(_T("key"), _T("allow_arguments"))
|
|---|
| 115 | OPTION(_T("default"), _T("false"))
|
|---|
| 116 | OPTION(_T("true_value"), _T("1"))
|
|---|
| 117 | OPTION(_T("false_value"), _T("0"))
|
|---|
| 118 | ITEM_END()
|
|---|
| 119 |
|
|---|
| 120 | ITEM_CHECK_BOOL(_T("allow_nasty_meta_chars"), _T("This might have security implications (depending on what you do with the options)"))
|
|---|
| 121 | ITEM_MAP_TO(_T("basic_ini_bool_mapper"))
|
|---|
| 122 | OPTION(_T("section"), _T("NRPE"))
|
|---|
| 123 | OPTION(_T("key"), _T("allow_nasty_meta_chars"))
|
|---|
| 124 | OPTION(_T("default"), _T("false"))
|
|---|
| 125 | OPTION(_T("true_value"), _T("1"))
|
|---|
| 126 | OPTION(_T("false_value"), _T("0"))
|
|---|
| 127 | ITEM_END()
|
|---|
| 128 |
|
|---|
| 129 | ITEM_CHECK_BOOL(_T("use_ssl"), _T("This option will enable SSL encryption on the NRPE data socket (this increases security somwhat."))
|
|---|
| 130 | ITEM_MAP_TO(_T("basic_ini_bool_mapper"))
|
|---|
| 131 | OPTION(_T("section"), _T("NRPE"))
|
|---|
| 132 | OPTION(_T("key"), _T("use_ssl"))
|
|---|
| 133 | OPTION(_T("default"), _T("true"))
|
|---|
| 134 | OPTION(_T("true_value"), _T("1"))
|
|---|
| 135 | OPTION(_T("false_value"), _T("0"))
|
|---|
| 136 | ITEM_END()
|
|---|
| 137 |
|
|---|
| 138 | PAGE_END()
|
|---|
| 139 | ADVANCED_PAGE(_T("Access configuration"))
|
|---|
| 140 |
|
|---|
| 141 | ITEM_EDIT_OPTIONAL_LIST(_T("Allow connection from:"), _T("This is the hosts that will be allowed to poll performance data from the NRPE server."))
|
|---|
| 142 | OPTION(_T("disabledCaption"), _T("Use global settings (defined previously)"))
|
|---|
| 143 | OPTION(_T("enabledCaption"), _T("Specify hosts for NRPE server"))
|
|---|
| 144 | OPTION(_T("listCaption"), _T("Add all IP addresses (not hosts) which should be able to connect:"))
|
|---|
| 145 | OPTION(_T("separator"), _T(","))
|
|---|
| 146 | OPTION(_T("disabled"), _T(""))
|
|---|
| 147 | ITEM_MAP_TO(_T("basic_ini_text_mapper"))
|
|---|
| 148 | OPTION(_T("section"), _T("NRPE"))
|
|---|
| 149 | OPTION(_T("key"), _T("allowed_hosts"))
|
|---|
| 150 | OPTION(_T("default"), _T(""))
|
|---|
| 151 | ITEM_END()
|
|---|
| 152 |
|
|---|
| 153 | PAGE_END()
|
|---|
| 154 | MODULE_SETTINGS_END()
|
|---|