source: nscp/service/simple_client.hpp @ cad08fb

0.4.00.4.10.4.2
Last change on this file since cad08fb was cad08fb, checked in by Michael Medin <michael@…>, 3 years ago

Major update with a new plugin glue that works better with *nix.
Everything should be the same but look tidier

  • Property mode set to 100644
File size: 2.7 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                void start() {
11                        core_->enableDebug(true);
12                        if (!core_->initCore(true)) {
13                                std::wcout << _T("Service *NOT* started!") << std::endl;
14                                return;
15                        }
16                        std::wcout << _T("Using settings from: ") << settings_manager::get_core()->get_settings_type_desc() << std::endl;
17                        std::wcout << _T("Enter command to inject or exit to terminate...") << std::endl;
18/*
19                        Settings::get_settings()->clear_cache();
20                        LOG_MESSAGE_STD( _T("test 001: ") + SETTINGS_GET_STRING(NSCLIENT_TEST1) );
21                        LOG_MESSAGE_STD( _T("test 002: ") + SETTINGS_GET_STRING(NSCLIENT_TEST2) );
22                        LOG_MESSAGE_STD( _T("test 003: ") + SETTINGS_GET_STRING(NSCLIENT_TEST3) );
23                        LOG_MESSAGE_STD( _T("test 004: ") + SETTINGS_GET_STRING(NSCLIENT_TEST4) );
24
25                        Settings::get_settings()->save_to(_T("test.ini"));
26*/
27                        std::wstring s = _T("");
28
29                        while (true) {
30                                std::wstring s;
31                                std::getline(std::wcin, s);
32                                if (s == _T("exit")) {
33                                        std::wcout << _T("Exiting...") << std::endl;
34                                        break;
35                                } else if (s == _T("plugins")) {
36                                        std::wcout << _T("Listing plugins...") << std::endl;
37                                        core_->listPlugins();
38                                } else if (s == _T("list")) {
39                                        std::wcout << _T("Listing commands...") << std::endl;
40                                        std::list<std::wstring> lst = core_->list_commands();
41                                        for (std::list<std::wstring>::const_iterator cit = lst.begin(); cit!=lst.end();++cit)
42                                                std::wcout << *cit << _T(": ") << core_->describeCommand(*cit) << std::endl;
43                                        std::wcout << _T("Listing commands...Done") << std::endl;
44                                } else if (s == _T("debug off")) {
45                                        std::wcout << _T("Setting debug log off...") << std::endl;
46                                        core_->enableDebug(false);
47                                } else if (s == _T("debug on")) {
48                                        std::wcout << _T("Setting debug log on...") << std::endl;
49                                        core_->enableDebug(true);
50                                } else if (s == _T("reattach")) {
51                                        std::wcout << _T("Reattaching to session 0") << std::endl;
52                                        core_->startTrayIcon(0);
53                                } else if (s == _T("assert")) {
54                                        throw "test";
55                                } else {
56                                        strEx::token t = strEx::getToken(s, ' ');
57                                        std::wstring msg, perf;
58                                        NSCAPI::nagiosReturn ret = core_->inject(t.first, t.second, msg, perf);
59                                        if (ret == NSCAPI::returnIgnored) {
60                                                std::wcout << _T("No handler for command: ") << t.first << std::endl;
61                                        } else {
62                                                std::wcout << nscapi::plugin_helper::translateReturn(ret) << _T(":");
63                                                std::wcout << msg;
64                                                if (!perf.empty())
65                                                        std::cout << "|" << strEx::wstring_to_string(perf);
66                                                std::wcout << std::endl;
67                                        }
68                                }
69                        }
70                        core_->exitCore(true);
71                }
72        };
73}
Note: See TracBrowser for help on using the repository browser.