source: nscp/modules/LUAScript/LUAScript.h @ 04ef932

0.4.00.4.10.4.2
Last change on this file since 04ef932 was 04ef932, checked in by Michael Medin <michael@…>, 22 months ago

2011-08-10

  • Fixed so it builds and runs on linux (but parser had issues so disabled som grammar rules whichneeds to be enabled again)
  • Added a lot of freatures and cleand up the PythonScript module
  • Started to merge som features from PythonScript back to Lua script


2011-08-07

  • Fixed a lot of issues with PythonScript module adding suport for alias and "raw command processing"
  • Fixed issue with loading plugins and aliases as well as duplicate plugin detection


2011-08-01

  • Property mode set to 100644
File size: 4.0 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***************************************************************************/
21NSC_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
33class LUAScript : public nscapi::impl::SimpleCommand, public script_wrapper::lua_handler, public nscapi::impl::simple_plugin {
34private:
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
57public:
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
89private:
90        typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsDiscSize> PathContainer;
91        typedef checkHolders::CheckContainer<checkHolders::MaxMinPercentageBoundsDiskSize> DriveContainer;
92};
Note: See TracBrowser for help on using the repository browser.