]> granicus.if.org Git - icinga2/blob - lib/cli/nodeutility.hpp
Cli: Ensure that repository path is created on 'node add' command
[icinga2] / lib / cli / nodeutility.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)    *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef AGENTUTILITY_H
21 #define AGENTUTILITY_H
22
23 #include "base/i2-base.hpp"
24 #include "base/dictionary.hpp"
25 #include "base/array.hpp"
26 #include "base/value.hpp"
27 #include "base/string.hpp"
28 #include <vector>
29
30 namespace icinga
31 {
32
33 /**
34  * @ingroup cli
35  */
36 class NodeUtility
37 {
38 public:
39         static String GetRepositoryPath(void);
40         static String GetNodeRepositoryFile(const String& name);
41         static String GetNodeSettingsFile(const String& name);
42         static void CreateRepositoryPath(void);
43         static std::vector<String> GetNodeCompletionSuggestions(const String& word);
44
45         static void PrintNodes(std::ostream& fp);
46         static void PrintNodesJson(std::ostream& fp);
47         static void PrintNodeRepository(std::ostream& fp, const Dictionary::Ptr& repository);
48         static void AddNode(const String& name);
49         static void AddNodeSettings(const String& name, const String& host, const String& port, double log_duration);
50         static void RemoveNode(const String& name);
51
52         static std::vector<Dictionary::Ptr> GetNodes(void);
53
54         static bool CreateBackupFile(const String& target);
55
56         static bool WriteNodeConfigObjects(const String& filename, const Array::Ptr& objects);
57
58         static void UpdateConstant(const String& name, const String& value);
59
60         /* node setup helpers */
61         static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const String& nodename, const String& zonename);
62         static int GenerateNodeMasterIcingaConfig(const String& nodename);
63
64         /* black/whitelist */
65         static String GetBlackAndWhiteListPath(const String& type);
66         static Array::Ptr GetBlackAndWhiteList(const String& type);
67         static int UpdateBlackAndWhiteList(const String& type, const String& node_filter,
68             const String& host_filter, const String& service_filter);
69         static int RemoveBlackAndWhiteList(const String& type, const String& node_filter,
70             const String& host_filter, const String& service_filter);
71         static int PrintBlackAndWhiteList(std::ostream& fp, const String& type);
72
73         static bool CheckAgainstBlackAndWhiteList(const String& type, const String& node, const String& host, const String& service);
74
75 private:
76         NodeUtility(void);
77         static bool RemoveNodeFile(const String& path);
78         static Dictionary::Ptr LoadNodeFile(const String& node_file);
79         static void CollectNodes(const String& node_file, std::vector<Dictionary::Ptr>& nodes);
80
81         static void SerializeObject(std::ostream& fp, const String& name, const String& type, const Dictionary::Ptr& object);
82         static void FormatValue(std::ostream& fp, const Value& val);
83         static void FormatArray(std::ostream& fp, const Array::Ptr& arr);
84 };
85
86 }
87
88 #endif /* AGENTUTILITY_H */