source: nscp/modules/DebugLogMetrics/DebugLogMetrics.cpp @ f7663c9

0.4.00.4.10.4.2
Last change on this file since f7663c9 was f0eb62d, checked in by Michael Medin <michael@…>, 4 years ago

Refactored service into its own project

  • Property mode set to 100644
File size: 6.2 KB
Line 
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
29DebugLogMetrics gDebugLogMetrics;
30
31BOOL 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
37DebugLogMetrics::DebugLogMetrics() : pdhThread(_T("debugThread")) {}
38DebugLogMetrics::~DebugLogMetrics() {}
39
40bool 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}
47bool 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
56bool DebugLogMetrics::hasCommandHandler() {
57        return true;
58}
59bool DebugLogMetrics::hasMessageHandler() {
60        return false;
61}
62/*
63void 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
81void getMetricsForName(std::wstring name) {
82
83}
84*/
85
86NSCAPI::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
94NSC_WRAPPERS_MAIN_DEF(gDebugLogMetrics);
95NSC_WRAPPERS_IGNORE_MSG_DEF();
96NSC_WRAPPERS_HANDLE_CMD_DEF(gDebugLogMetrics);
97NSC_WRAPPERS_HANDLE_CONFIGURATION(gDebugLogMetrics);
98
99
100MODULE_SETTINGS_START(DebugLogMetrics, _T("NRPE Listener configuration"), _T("..."))
101
102PAGE(_T("NRPE Listsner configuration"))
103
104ITEM_EDIT_TEXT(_T("port"), _T("This is the port the DebugLogMetrics.dll will listen to."))
105ITEM_MAP_TO(_T("basic_ini_text_mapper"))
106OPTION(_T("section"), _T("NRPE"))
107OPTION(_T("key"), _T("port"))
108OPTION(_T("default"), _T("5666"))
109ITEM_END()
110
111ITEM_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."))
112ITEM_MAP_TO(_T("basic_ini_bool_mapper"))
113OPTION(_T("section"), _T("NRPE"))
114OPTION(_T("key"), _T("allow_arguments"))
115OPTION(_T("default"), _T("false"))
116OPTION(_T("true_value"), _T("1"))
117OPTION(_T("false_value"), _T("0"))
118ITEM_END()
119
120ITEM_CHECK_BOOL(_T("allow_nasty_meta_chars"), _T("This might have security implications (depending on what you do with the options)"))
121ITEM_MAP_TO(_T("basic_ini_bool_mapper"))
122OPTION(_T("section"), _T("NRPE"))
123OPTION(_T("key"), _T("allow_nasty_meta_chars"))
124OPTION(_T("default"), _T("false"))
125OPTION(_T("true_value"), _T("1"))
126OPTION(_T("false_value"), _T("0"))
127ITEM_END()
128
129ITEM_CHECK_BOOL(_T("use_ssl"), _T("This option will enable SSL encryption on the NRPE data socket (this increases security somwhat."))
130ITEM_MAP_TO(_T("basic_ini_bool_mapper"))
131OPTION(_T("section"), _T("NRPE"))
132OPTION(_T("key"), _T("use_ssl"))
133OPTION(_T("default"), _T("true"))
134OPTION(_T("true_value"), _T("1"))
135OPTION(_T("false_value"), _T("0"))
136ITEM_END()
137
138PAGE_END()
139ADVANCED_PAGE(_T("Access configuration"))
140
141ITEM_EDIT_OPTIONAL_LIST(_T("Allow connection from:"), _T("This is the hosts that will be allowed to poll performance data from the NRPE server."))
142OPTION(_T("disabledCaption"), _T("Use global settings (defined previously)"))
143OPTION(_T("enabledCaption"), _T("Specify hosts for NRPE server"))
144OPTION(_T("listCaption"), _T("Add all IP addresses (not hosts) which should be able to connect:"))
145OPTION(_T("separator"), _T(","))
146OPTION(_T("disabled"), _T(""))
147ITEM_MAP_TO(_T("basic_ini_text_mapper"))
148OPTION(_T("section"), _T("NRPE"))
149OPTION(_T("key"), _T("allowed_hosts"))
150OPTION(_T("default"), _T(""))
151ITEM_END()
152
153PAGE_END()
154MODULE_SETTINGS_END()
Note: See TracBrowser for help on using the repository browser.