mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-09-26 03:19:05 +02:00
2008-12-16 Ramon Novoa <rnovoa@artica.es>
* win32/modules/pandora_module_wmiquery.cc, win32/modules/pandora_module_wmiquery.h: Added to repository. WMI query module. * win32/windows/pandora_wmi.cc, win32/windows/pandora_wmi.h, win32/modules/pandora_module.h, win32/modules/pandora_module_factory.cc, win32/modules/pandora_module_list.cc, win32/modules/pandora_module.cc, win32/PandoraAgent.dev: Added support for WMI query module. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1294 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
caf5492185
commit
c64614fda3
@ -1,3 +1,17 @@
|
|||||||
|
2008-12-16 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
|
* win32/modules/pandora_module_wmiquery.cc,
|
||||||
|
win32/modules/pandora_module_wmiquery.h: Added to repository. WMI
|
||||||
|
query module.
|
||||||
|
|
||||||
|
* win32/windows/pandora_wmi.cc,
|
||||||
|
win32/windows/pandora_wmi.h,
|
||||||
|
win32/modules/pandora_module.h,
|
||||||
|
win32/modules/pandora_module_factory.cc,
|
||||||
|
win32/modules/pandora_module_list.cc,
|
||||||
|
win32/modules/pandora_module.cc,
|
||||||
|
win32/PandoraAgent.dev: Added support for WMI query module.
|
||||||
|
|
||||||
2008-12-11 Evi Vanoost <vanooste@rcbi.rochester.edu>
|
2008-12-11 Evi Vanoost <vanooste@rcbi.rochester.edu>
|
||||||
|
|
||||||
* linux/plugins/SGE: Added the SGE plugin
|
* linux/plugins/SGE: Added the SGE plugin
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[Project]
|
[Project]
|
||||||
FileName=PandoraAgent.dev
|
FileName=PandoraAgent.dev
|
||||||
Name=PandoraAgent
|
Name=PandoraAgent
|
||||||
UnitCount=79
|
UnitCount=81
|
||||||
Type=1
|
Type=1
|
||||||
Ver=1
|
Ver=1
|
||||||
ObjFiles=
|
ObjFiles=
|
||||||
@ -837,3 +837,23 @@ Priority=1000
|
|||||||
OverrideBuildCmd=0
|
OverrideBuildCmd=0
|
||||||
BuildCmd=
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit80]
|
||||||
|
FileName=modules\pandora_module_wmiquery.cc
|
||||||
|
CompileCpp=1
|
||||||
|
Folder=Modules
|
||||||
|
Compile=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit81]
|
||||||
|
FileName=modules\pandora_module_wmiquery.h
|
||||||
|
CompileCpp=1
|
||||||
|
Folder=Modules
|
||||||
|
Compile=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
@ -120,8 +120,9 @@ Pandora_Module::parseModuleKindFromString (string kind) {
|
|||||||
} else if (kind == module_odbc_str) {
|
} else if (kind == module_odbc_str) {
|
||||||
return MODULE_ODBC;
|
return MODULE_ODBC;
|
||||||
} else if (kind == module_logevent_str) {
|
} else if (kind == module_logevent_str) {
|
||||||
|
|
||||||
return MODULE_LOGEVENT;
|
return MODULE_LOGEVENT;
|
||||||
|
} else if (kind == module_wmiquery_str) {
|
||||||
|
return MODULE_WMIQUERY;
|
||||||
} else {
|
} else {
|
||||||
return MODULE_0;
|
return MODULE_0;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,8 @@ namespace Pandora_Modules {
|
|||||||
MODULE_FREEMEMORY, /**< The module checks the amount of
|
MODULE_FREEMEMORY, /**< The module checks the amount of
|
||||||
* freememory in the system */
|
* freememory in the system */
|
||||||
MODULE_ODBC, /**< The module performs a SQL query via ODBC */
|
MODULE_ODBC, /**< The module performs a SQL query via ODBC */
|
||||||
MODULE_LOGEVENT /**< The module checks for log events */
|
MODULE_LOGEVENT, /**< The module checks for log events */
|
||||||
|
MODULE_WMIQUERY /**< The module runs WQL queries */
|
||||||
} Module_Kind;
|
} Module_Kind;
|
||||||
|
|
||||||
const string module_exec_str = "module_exec";
|
const string module_exec_str = "module_exec";
|
||||||
@ -81,6 +82,7 @@ namespace Pandora_Modules {
|
|||||||
const string module_cpuusage_str = "module_cpuusage";
|
const string module_cpuusage_str = "module_cpuusage";
|
||||||
const string module_odbc_str = "module_odbc";
|
const string module_odbc_str = "module_odbc";
|
||||||
const string module_logevent_str = "module_logevent";
|
const string module_logevent_str = "module_logevent";
|
||||||
|
const string module_wmiquery_str = "module_wmiquery";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pandora module super-class exception.
|
* Pandora module super-class exception.
|
||||||
@ -102,7 +104,8 @@ namespace Pandora_Modules {
|
|||||||
*/
|
*/
|
||||||
class Interval_Not_Fulfilled : public Pandora_Modules::Module_Exception { };
|
class Interval_Not_Fulfilled : public Pandora_Modules::Module_Exception { };
|
||||||
|
|
||||||
/**
* Pandora module super-class.
|
/**
|
||||||
|
* Pandora module super-class.
|
||||||
*
|
*
|
||||||
* Every defined module must inherit of this class.
|
* Every defined module must inherit of this class.
|
||||||
*/
|
*/
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "pandora_module_cpuusage.h"
|
#include "pandora_module_cpuusage.h"
|
||||||
#include "pandora_module_odbc.h"
|
#include "pandora_module_odbc.h"
|
||||||
#include "pandora_module_logevent.h"
|
#include "pandora_module_logevent.h"
|
||||||
|
#include "pandora_module_wmiquery.h"
|
||||||
#include "../pandora_strutils.h"
|
#include "../pandora_strutils.h"
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@ -57,6 +58,8 @@ using namespace Pandora_Strutils;
|
|||||||
#define TOKEN_ASYNC ("module_async")
|
#define TOKEN_ASYNC ("module_async")
|
||||||
#define TOKEN_WATCHDOG ("module_watchdog ")
|
#define TOKEN_WATCHDOG ("module_watchdog ")
|
||||||
#define TOKEN_START_COMMAND ("module_start_command ")
|
#define TOKEN_START_COMMAND ("module_start_command ")
|
||||||
|
#define TOKEN_WMIQUERY ("module_wmiquery ")
|
||||||
|
#define TOKEN_WMICOLUMN ("module_wmicolumn ")
|
||||||
|
|
||||||
string
|
string
|
||||||
parseLine (string line, string token) {
|
parseLine (string line, string token) {
|
||||||
@ -94,6 +97,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||||||
string module_logevent, module_source, module_eventtype, module_eventcode;
|
string module_logevent, module_source, module_eventtype, module_eventcode;
|
||||||
string module_pattern, module_async;
|
string module_pattern, module_async;
|
||||||
string module_watchdog, module_start_command;
|
string module_watchdog, module_start_command;
|
||||||
|
string module_wmiquery, module_wmicolumn;
|
||||||
Pandora_Module *module;
|
Pandora_Module *module;
|
||||||
bool numeric;
|
bool numeric;
|
||||||
Module_Type type;
|
Module_Type type;
|
||||||
@ -118,6 +122,8 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||||||
module_async = "";
|
module_async = "";
|
||||||
module_watchdog = "";
|
module_watchdog = "";
|
||||||
module_start_command = "";
|
module_start_command = "";
|
||||||
|
module_wmiquery = "";
|
||||||
|
module_wmicolumn = "";
|
||||||
|
|
||||||
stringtok (tokens, definition, "\n");
|
stringtok (tokens, definition, "\n");
|
||||||
|
|
||||||
@ -194,6 +200,12 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||||||
if (module_watchdog == "") {
|
if (module_watchdog == "") {
|
||||||
module_watchdog = parseLine (line, TOKEN_WATCHDOG);
|
module_watchdog = parseLine (line, TOKEN_WATCHDOG);
|
||||||
}
|
}
|
||||||
|
if (module_wmiquery == "") {
|
||||||
|
module_wmiquery = parseLine (line, TOKEN_WMIQUERY);
|
||||||
|
}
|
||||||
|
if (module_wmicolumn == "") {
|
||||||
|
module_wmicolumn = parseLine (line, TOKEN_WMICOLUMN);
|
||||||
|
}
|
||||||
|
|
||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
@ -263,6 +275,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||||||
module_eventtype,
|
module_eventtype,
|
||||||
module_eventcode,
|
module_eventcode,
|
||||||
module_pattern);
|
module_pattern);
|
||||||
|
} else if (module_wmiquery != "") {
|
||||||
|
module = new Pandora_Module_WMIQuery (module_name,
|
||||||
|
module_wmiquery, module_wmicolumn);
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "pandora_module_cpuusage.h"
|
#include "pandora_module_cpuusage.h"
|
||||||
#include "pandora_module_odbc.h"
|
#include "pandora_module_odbc.h"
|
||||||
#include "pandora_module_logevent.h"
|
#include "pandora_module_logevent.h"
|
||||||
|
#include "pandora_module_wmiquery.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -135,6 +136,7 @@ Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition)
|
|||||||
Pandora_Module_Freememory *module_freememory;
|
Pandora_Module_Freememory *module_freememory;
|
||||||
Pandora_Module_Odbc *module_odbc;
|
Pandora_Module_Odbc *module_odbc;
|
||||||
Pandora_Module_Logevent *module_logevent;
|
Pandora_Module_Logevent *module_logevent;
|
||||||
|
Pandora_Module_WMIQuery *module_wmiquery;
|
||||||
|
|
||||||
module = Pandora_Module_Factory::getModuleFromDefinition (definition);
|
module = Pandora_Module_Factory::getModuleFromDefinition (definition);
|
||||||
|
|
||||||
@ -180,6 +182,10 @@ Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition)
|
|||||||
module_logevent = (Pandora_Module_Logevent *) module;
|
module_logevent = (Pandora_Module_Logevent *) module;
|
||||||
modules->push_back (module_logevent);
|
modules->push_back (module_logevent);
|
||||||
break;
|
break;
|
||||||
|
case MODULE_WMIQUERY:
|
||||||
|
module_wmiquery = (Pandora_Module_WMIQuery *) module;
|
||||||
|
modules->push_back (module_wmiquery);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
69
pandora_agents/win32/modules/pandora_module_wmiquery.cc
Normal file
69
pandora_agents/win32/modules/pandora_module_wmiquery.cc
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/* Pandora wmiquery module. This module runs WQL queries.
|
||||||
|
|
||||||
|
Copyright (C) 2008 Artica ST.
|
||||||
|
Written by Ramon Novoa.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pandora_module_wmiquery.h"
|
||||||
|
#include "../windows/pandora_wmi.h"
|
||||||
|
#include "../pandora_windows_service.h"
|
||||||
|
|
||||||
|
using namespace Pandora;
|
||||||
|
using namespace Pandora_Modules;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Pandora_Module_WMIQuery object.
|
||||||
|
*
|
||||||
|
* @param name Module name.
|
||||||
|
*/
|
||||||
|
Pandora_Module_WMIQuery::Pandora_Module_WMIQuery (string name, string query, string column)
|
||||||
|
: Pandora_Module (name) {
|
||||||
|
|
||||||
|
this->query = query;
|
||||||
|
this->column = column;
|
||||||
|
this->setKind (module_wmiquery_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Pandora_Module_WMIQuery::run () {
|
||||||
|
string value;
|
||||||
|
list<string> rows;
|
||||||
|
list<string>::iterator row;
|
||||||
|
|
||||||
|
// Run
|
||||||
|
try {
|
||||||
|
Pandora_Module::run ();
|
||||||
|
} catch (Interval_Not_Fulfilled e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->query.empty () || this->column.empty ()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pandora_Wmi::runWMIQuery (this->query, this->column, rows);
|
||||||
|
|
||||||
|
// No data
|
||||||
|
if (rows.size () < 1) {
|
||||||
|
this->setOutput ("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (row = rows.begin (); row != rows.end(); ++row) {
|
||||||
|
this->setOutput (*row);
|
||||||
|
}
|
||||||
|
}
|
42
pandora_agents/win32/modules/pandora_module_wmiquery.h
Normal file
42
pandora_agents/win32/modules/pandora_module_wmiquery.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* Pandora wmiquery module header file.
|
||||||
|
|
||||||
|
Copyright (C) 2008 Artica ST.
|
||||||
|
Written by Ramon Novoa.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PANDORA_MODULE_WMIQUERY_H__
|
||||||
|
#define __PANDORA_MODULE_WMIQUERY_H__
|
||||||
|
|
||||||
|
#include "pandora_module.h"
|
||||||
|
|
||||||
|
namespace Pandora_Modules {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This module runs WQL queries.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Pandora_Module_WMIQuery : public Pandora_Module {
|
||||||
|
private:
|
||||||
|
string query;
|
||||||
|
string column;
|
||||||
|
public:
|
||||||
|
Pandora_Module_WMIQuery (string name, string query, string column);
|
||||||
|
void run ();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -632,3 +632,40 @@ Pandora_Wmi::stopService (string service_name) {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs a generic WQL query.
|
||||||
|
*
|
||||||
|
* @param wmi_query WQL query.
|
||||||
|
* @param column Column to retrieve from the query result.
|
||||||
|
* @param rows List where the query result will be placed.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Pandora_Wmi::runWMIQuery (string wmi_query, string column, list<string> &rows) {
|
||||||
|
CDhInitialize init;
|
||||||
|
CDispPtr wmi_svc, quickfixes;
|
||||||
|
char *value = NULL;
|
||||||
|
wstring column_w(column.length(), L' ');
|
||||||
|
wstring wmi_query_w(wmi_query.length(), L' ');
|
||||||
|
|
||||||
|
// Copy string to wstring.
|
||||||
|
std::copy(column.begin(), column.end(), column_w.begin());
|
||||||
|
std::copy(wmi_query.begin(), wmi_query.end(), wmi_query_w.begin());
|
||||||
|
|
||||||
|
try {
|
||||||
|
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
|
||||||
|
dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc,
|
||||||
|
L".ExecQuery(%S)",
|
||||||
|
wmi_query_w.c_str ()));
|
||||||
|
FOR_EACH (quickfix, quickfixes, NULL) {
|
||||||
|
dhGetValue (L"%s", &value, quickfix,
|
||||||
|
column_w.c_str ());
|
||||||
|
rows.push_back (value);
|
||||||
|
dhFreeString (value);
|
||||||
|
} NEXT_THROW (quickfix);
|
||||||
|
} catch (string errstr) {
|
||||||
|
pandoraLog ("runWMIQuery error. %s", errstr.c_str ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,6 +61,9 @@ namespace Pandora_Wmi {
|
|||||||
bool runProgram (string command);
|
bool runProgram (string command);
|
||||||
bool startService (string service_name);
|
bool startService (string service_name);
|
||||||
bool stopService (string service_name);
|
bool stopService (string service_name);
|
||||||
|
void runWMIQuery (string wmi_query,
|
||||||
|
string var,
|
||||||
|
list<string> &rows);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user