2014-10-17 15:13:17 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-10-17 18:55:34 +02:00
|
|
|
#ifndef AGENTUTILITY_H
|
|
|
|
#define AGENTUTILITY_H
|
|
|
|
|
|
|
|
#include "base/i2-base.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
|
|
|
|
*/
|
2014-10-31 11:38:16 +01:00
|
|
|
class 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);
|
|
|
|
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
|
|
|
|
2014-10-22 15:29:54 +02:00
|
|
|
static bool CreateBackupFile(const String& target);
|
|
|
|
|
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 */
|
2014-10-31 22:21:36 +01:00
|
|
|
static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const String& nodename, const String& zonename);
|
2014-10-31 11:38:16 +01:00
|
|
|
static int GenerateNodeMasterIcingaConfig(const String& nodename);
|
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
|
|
|
|
|
|
|
static void SerializeObject(std::ostream& fp, const String& name, const String& type, const Dictionary::Ptr& object);
|
|
|
|
static void FormatValue(std::ostream& fp, const Value& val);
|
|
|
|
static void FormatArray(std::ostream& fp, const Array::Ptr& arr);
|
2014-10-17 15:13:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-10-17 18:55:34 +02:00
|
|
|
#endif /* AGENTUTILITY_H */
|