| 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 | NSC_WRAPPERS_MAIN();
|
|---|
| 22 | #include <config.h>
|
|---|
| 23 | #include <strEx.h>
|
|---|
| 24 | #include <utils.h>
|
|---|
| 25 | #include <checkHelpers.hpp>
|
|---|
| 26 | #include "script_wrapper.hpp"
|
|---|
| 27 |
|
|---|
| 28 | class LUAScript : script_wrapper::lua_handler {
|
|---|
| 29 | private:
|
|---|
| 30 |
|
|---|
| 31 | class lua_func {
|
|---|
| 32 | public:
|
|---|
| 33 | lua_func(script_wrapper::lua_script* script_, std::wstring function_) : script(script_), function(function_) {}
|
|---|
| 34 | lua_func() : script(NULL) {}
|
|---|
| 35 | script_wrapper::lua_script* script;
|
|---|
| 36 | std::wstring function;
|
|---|
| 37 |
|
|---|
| 38 | NSCAPI::nagiosReturn handleCommand(lua_handler *handler, strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf) const {
|
|---|
| 39 | return script->handleCommand(handler, function, command, argLen, char_args, msg, perf);
|
|---|
| 40 | }
|
|---|
| 41 | };
|
|---|
| 42 |
|
|---|
| 43 | typedef std::map<strEx::blindstr,lua_func> cmd_list;
|
|---|
| 44 | typedef std::list<script_wrapper::lua_script*> script_list;
|
|---|
| 45 |
|
|---|
| 46 | cmd_list commands_;
|
|---|
| 47 | script_list scripts_;
|
|---|
| 48 |
|
|---|
| 49 | public:
|
|---|
| 50 | LUAScript();
|
|---|
| 51 | virtual ~LUAScript();
|
|---|
| 52 | // Module calls
|
|---|
| 53 | bool loadModule();
|
|---|
| 54 | bool unloadModule();
|
|---|
| 55 | bool reload(std::wstring &msg);
|
|---|
| 56 |
|
|---|
| 57 | std::wstring getModuleName() {
|
|---|
| 58 | return _T("LUAScript");
|
|---|
| 59 | }
|
|---|
| 60 | std::wstring getModuleDescription() {
|
|---|
| 61 | return _T("LUAScript...");
|
|---|
| 62 | }
|
|---|
| 63 | NSCModuleWrapper::module_version getModuleVersion() {
|
|---|
| 64 | NSCModuleWrapper::module_version version = {0, 0, 1 };
|
|---|
| 65 | return version;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | bool hasCommandHandler();
|
|---|
| 69 | bool hasMessageHandler();
|
|---|
| 70 | bool loadScript(const std::wstring script);
|
|---|
| 71 | NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf);
|
|---|
| 72 | //NSCAPI::nagiosReturn RunLUA(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf);
|
|---|
| 73 | //NSCAPI::nagiosReturn extract_return(Lua_State &L, int arg_count, std::wstring &message, std::wstring &perf);
|
|---|
| 74 |
|
|---|
| 75 | //script_wrapper::lua_handler
|
|---|
| 76 | void register_command(script_wrapper::lua_script* script, std::wstring command, std::wstring function);
|
|---|
| 77 |
|
|---|
| 78 | private:
|
|---|
| 79 | typedef checkHolders::CheckConatiner<checkHolders::MaxMinBoundsDiscSize> PathConatiner;
|
|---|
| 80 | typedef checkHolders::CheckConatiner<checkHolders::MaxMinPercentageBoundsDiskSize> DriveConatiner;
|
|---|
| 81 | }; |
|---|