2014-10-17 15:13:17 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2015-01-22 12:00:23 +01:00
|
|
|
* Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
|
2014-10-17 15:13:17 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2015-06-24 14:13:54 +02:00
|
|
|
#ifndef NODEUTILITY_H
|
|
|
|
#define NODEUTILITY_H
|
2014-10-17 18:55:34 +02:00
|
|
|
|
|
|
|
#include "base/i2-base.hpp"
|
2015-02-26 11:04:57 +01:00
|
|
|
#include "cli/i2-cli.hpp"
|
2014-10-18 21:06:28 +02:00
|
|
|
#include "base/dictionary.hpp"
|
2014-10-21 21:33:21 +02:00
|
|
|
#include "base/array.hpp"
|
|
|
|
#include "base/value.hpp"
|
2014-10-18 21:06:28 +02:00
|
|
|
#include "base/string.hpp"
|
2014-10-21 13:54:56 +02:00
|
|
|
#include <vector>
|
2014-10-17 15:13:17 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup cli
|
|
|
|
*/
|
2015-02-26 11:04:57 +01:00
|
|
|
class I2_CLI_API NodeUtility
|
2014-10-17 18:55:34 +02:00
|
|
|
{
|
2014-10-17 15:13:17 +02:00
|
|
|
public:
|
2014-10-18 21:06:28 +02:00
|
|
|
static String GetRepositoryPath(void);
|
2014-10-31 11:38:16 +01:00
|
|
|
static String GetNodeRepositoryFile(const String& name);
|
|
|
|
static String GetNodeSettingsFile(const String& name);
|
2014-12-04 17:22:09 +01:00
|
|
|
static void CreateRepositoryPath(const String& path = GetRepositoryPath());
|
2014-10-31 11:38:16 +01:00
|
|
|
static std::vector<String> GetNodeCompletionSuggestions(const String& word);
|
2014-10-18 21:06:28 +02:00
|
|
|
|
2014-10-31 11:38:16 +01:00
|
|
|
static void PrintNodes(std::ostream& fp);
|
|
|
|
static void PrintNodesJson(std::ostream& fp);
|
|
|
|
static void PrintNodeRepository(std::ostream& fp, const Dictionary::Ptr& repository);
|
|
|
|
static void AddNode(const String& name);
|
|
|
|
static void AddNodeSettings(const String& name, const String& host, const String& port, double log_duration);
|
|
|
|
static void RemoveNode(const String& name);
|
2014-10-18 21:06:28 +02:00
|
|
|
|
2014-10-31 11:38:16 +01:00
|
|
|
static std::vector<Dictionary::Ptr> GetNodes(void);
|
2014-10-17 15:13:17 +02:00
|
|
|
|
2015-02-09 14:04:00 +01:00
|
|
|
static bool CreateBackupFile(const String& target, bool is_private = false);
|
2014-10-22 15:29:54 +02:00
|
|
|
|
2014-10-31 11:38:16 +01:00
|
|
|
static bool WriteNodeConfigObjects(const String& filename, const Array::Ptr& objects);
|
2014-10-21 21:33:21 +02:00
|
|
|
|
2014-10-23 15:05:12 +02:00
|
|
|
static void UpdateConstant(const String& name, const String& value);
|
2014-10-22 19:27:21 +02:00
|
|
|
|
2014-10-31 11:53:44 +01:00
|
|
|
/* node setup helpers */
|
2015-11-25 17:41:03 +01:00
|
|
|
static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints);
|
|
|
|
static int GenerateNodeMasterIcingaConfig(void);
|
2014-10-22 15:29:54 +02:00
|
|
|
|
2014-10-29 13:53:59 +01:00
|
|
|
/* black/whitelist */
|
2014-10-30 00:29:09 +01:00
|
|
|
static String GetBlackAndWhiteListPath(const String& type);
|
2014-10-31 16:21:07 +01:00
|
|
|
static Array::Ptr GetBlackAndWhiteList(const String& type);
|
2014-10-31 11:53:44 +01:00
|
|
|
static int UpdateBlackAndWhiteList(const String& type, const String& node_filter,
|
2014-10-29 13:53:59 +01:00
|
|
|
const String& host_filter, const String& service_filter);
|
2014-10-31 11:53:44 +01:00
|
|
|
static int RemoveBlackAndWhiteList(const String& type, const String& node_filter,
|
2014-10-29 13:53:59 +01:00
|
|
|
const String& host_filter, const String& service_filter);
|
|
|
|
static int PrintBlackAndWhiteList(std::ostream& fp, const String& type);
|
|
|
|
|
2014-10-31 11:53:44 +01:00
|
|
|
static bool CheckAgainstBlackAndWhiteList(const String& type, const String& node, const String& host, const String& service);
|
2014-10-30 00:29:09 +01:00
|
|
|
|
2014-10-17 18:55:34 +02:00
|
|
|
private:
|
2014-10-31 11:38:16 +01:00
|
|
|
NodeUtility(void);
|
|
|
|
static bool RemoveNodeFile(const String& path);
|
2014-10-31 11:53:44 +01:00
|
|
|
static Dictionary::Ptr LoadNodeFile(const String& node_file);
|
|
|
|
static void CollectNodes(const String& node_file, std::vector<Dictionary::Ptr>& nodes);
|
2014-10-21 21:33:21 +02:00
|
|
|
|
2015-11-25 17:41:03 +01:00
|
|
|
static void SerializeObject(std::ostream& fp, const Dictionary::Ptr& object);
|
2014-10-17 15:13:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-24 14:13:54 +02:00
|
|
|
#endif /* NODEUTILITY_H */
|