1 /******************************************************************************
3 * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
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. *
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. *
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 ******************************************************************************/
20 #ifndef AGENTUTILITY_H
21 #define AGENTUTILITY_H
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"
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);
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);
52 static std::vector<Dictionary::Ptr> GetNodes(void);
54 static bool CreateBackupFile(const String& target);
56 static bool WriteNodeConfigObjects(const String& filename, const Array::Ptr& objects);
58 static void UpdateConstant(const String& name, const String& value);
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);
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);
73 static bool CheckAgainstBlackAndWhiteList(const String& type, const String& node, const String& host, const String& service);
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);
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);
88 #endif /* AGENTUTILITY_H */