source: nscp/service/simple_client.hpp @ 8840f09

0.4.00.4.10.4.2
Last change on this file since 8840f09 was 04ef932, checked in by Michael Medin <michael@…>, 23 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: 2.8 KB
Line 
1#pragma once
2#include <nscapi/nscapi_helper.hpp>
3
4class NSClientT;
5namespace nsclient {
6        class simple_client {
7                NSClient *core_;
8        public:
9                simple_client(NSClient *core) : core_(core) {}
10
11                void log(std::wstring msg) {
12                        std::string s = nsclient::logger_helper::create_info(__FILE__, __LINE__, msg);
13                        core_->reportMessage(s);
14                }
15                void start() {
16                        core_->enableDebug(true);
17                        if (!core_->initCore(true)) {
18                                core_->log_error(__FILE__, __LINE__, _T("Service failed to start"));
19                                return;
20                        }
21
22                        if (core_->get_service_control().is_started())
23                                core_->log_info(__FILE__, __LINE__, _T("Service seems to be started (Sockets and such will probably not work)..."));
24
25                        //std::wcout << _T("Using settings from: ") << settings_manager::get_core()->get_settings_type_desc() << std::endl;
26                        core_->log_info(__FILE__, __LINE__, _T("Enter command to inject or exit to terminate..."));
27/*
28                        Settings::get_settings()->clear_cache();
29                        LOG_MESSAGE_STD( _T("test 001: ") + SETTINGS_GET_STRING(NSCLIENT_TEST1) );
30                        LOG_MESSAGE_STD( _T("test 002: ") + SETTINGS_GET_STRING(NSCLIENT_TEST2) );
31                        LOG_MESSAGE_STD( _T("test 003: ") + SETTINGS_GET_STRING(NSCLIENT_TEST3) );
32                        LOG_MESSAGE_STD( _T("test 004: ") + SETTINGS_GET_STRING(NSCLIENT_TEST4) );
33
34                        Settings::get_settings()->save_to(_T("test.ini"));
35*/
36                        std::wstring s = _T("");
37
38                        while (true) {
39                                std::wstring s;
40                                std::getline(std::wcin, s);
41                                if (s == _T("exit")) {
42                                        log(_T("Exiting..."));
43                                        break;
44                                } else if (s == _T("plugins")) {
45                                        log(_T("Plugins: "));
46                                        core_->listPlugins();
47                                } else if (s == _T("list") || s == _T("commands")) {
48                                        log(_T("Commands:"));
49                                        std::list<std::wstring> lst = core_->list_commands();
50                                        for (std::list<std::wstring>::const_iterator cit = lst.begin(); cit!=lst.end();++cit)
51                                                log(_T("| ") + *cit + _T(": ") + core_->describeCommand(*cit));
52                                } else if (s == _T("debug off")) {
53                                        log(_T("Setting debug log off..."));
54                                        core_->enableDebug(false);
55                                } else if (s == _T("debug on")) {
56                                        log(_T("Setting debug log on..."));
57                                        core_->enableDebug(true);
58                                } else if (s == _T("reattach")) {
59                                        log(_T("Reattaching to session 0"));
60                                        core_->startTrayIcon(0);
61                                } else if (s == _T("assert")) {
62                                        int *foo = 0;
63                                        *foo = 0;
64                                        throw "test";
65                                } else {
66                                        strEx::token t = strEx::getToken(s, ' ');
67                                        std::wstring msg, perf;
68                                        NSCAPI::nagiosReturn ret = core_->inject(t.first, t.second, msg, perf);
69                                        if (ret == NSCAPI::returnIgnored) {
70                                                log(_T("No handler for command: ") + t.first);
71                                        } else {
72                                                log(nscapi::plugin_helper::translateReturn(ret) + _T(":") + msg);
73                                                if (!perf.empty())
74                                                        log(_T(" Perfoamcen data: ") + perf);
75                                        }
76                                }
77                        }
78                        core_->exitCore(true);
79                }
80        };
81}
Note: See TracBrowser for help on using the repository browser.