| 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 | #include <boost/optional.hpp>
|
|---|
| 29 |
|
|---|
| 30 | #include <scripts/functions.hpp>
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | class LUAScript : public nscapi::impl::SimpleCommand, public script_wrapper::lua_handler, public nscapi::impl::simple_plugin {
|
|---|
| 34 | private:
|
|---|
| 35 |
|
|---|
| 36 | class lua_func {
|
|---|
| 37 | public:
|
|---|
| 38 | lua_func(script_wrapper::lua_script* script_, std::wstring function_) : script(script_), function(function_) {}
|
|---|
| 39 | lua_func() : script(NULL) {}
|
|---|
| 40 | script_wrapper::lua_script* script;
|
|---|
| 41 | std::wstring function;
|
|---|
| 42 |
|
|---|
| 43 | NSCAPI::nagiosReturn handleCommand(lua_handler *handler, std::wstring command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) const {
|
|---|
| 44 | return script->handleCommand(handler, function, command, arguments, msg, perf);
|
|---|
| 45 | }
|
|---|
| 46 | };
|
|---|
| 47 |
|
|---|
| 48 | script_container::list_type scripts_;
|
|---|
| 49 |
|
|---|
| 50 | typedef std::map<std::wstring,lua_func> cmd_list;
|
|---|
| 51 | typedef std::list<boost::shared_ptr<script_wrapper::lua_script> > script_list;
|
|---|
| 52 |
|
|---|
| 53 | cmd_list commands_;
|
|---|
| 54 | script_list instances_;
|
|---|
| 55 | boost::filesystem::wpath root_;
|
|---|
| 56 |
|
|---|
| 57 | public:
|
|---|
| 58 | LUAScript();
|
|---|
| 59 | virtual ~LUAScript();
|
|---|
| 60 | // Module calls
|
|---|
| 61 | bool loadModule();
|
|---|
| 62 | bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode);
|
|---|
| 63 |
|
|---|
| 64 | bool unloadModule();
|
|---|
| 65 | bool reload(std::wstring &msg);
|
|---|
| 66 |
|
|---|
| 67 | std::wstring getModuleName() {
|
|---|
| 68 | return _T("LUAScript");
|
|---|
| 69 | }
|
|---|
| 70 | std::wstring getModuleDescription() {
|
|---|
| 71 | return _T("LUAScript...");
|
|---|
| 72 | }
|
|---|
| 73 | nscapi::plugin_wrapper::module_version getModuleVersion() {
|
|---|
| 74 | nscapi::plugin_wrapper::module_version version = {0, 0, 1 };
|
|---|
| 75 | return version;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | bool hasCommandHandler();
|
|---|
| 79 | bool hasMessageHandler();
|
|---|
| 80 | boost::optional<boost::filesystem::wpath> find_file(std::wstring file);
|
|---|
| 81 | bool loadScript(std::wstring alias, std::wstring file);
|
|---|
| 82 | NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);
|
|---|
| 83 | //NSCAPI::nagiosReturn RunLUA(const unsigned int argLen, wchar_t **char_args, std::wstring &message, std::wstring &perf);
|
|---|
| 84 | //NSCAPI::nagiosReturn extract_return(Lua_State &L, int arg_count, std::wstring &message, std::wstring &perf);
|
|---|
| 85 |
|
|---|
| 86 | //script_wrapper::lua_handler
|
|---|
| 87 | void register_command(script_wrapper::lua_script* script, std::wstring command, std::wstring function);
|
|---|
| 88 |
|
|---|
| 89 | private:
|
|---|
| 90 | typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsDiscSize> PathContainer;
|
|---|
| 91 | typedef checkHolders::CheckContainer<checkHolders::MaxMinPercentageBoundsDiskSize> DriveContainer;
|
|---|
| 92 | };
|
|---|