mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
parent
f94abac18f
commit
153693d284
@ -56,8 +56,9 @@ void ObjectListCommand::InitParameters(boost::program_options::options_descripti
|
|||||||
boost::program_options::options_description& hiddenDesc,
|
boost::program_options::options_description& hiddenDesc,
|
||||||
ArgumentCompletionDescription& argCompletionDesc) const
|
ArgumentCompletionDescription& argCompletionDesc) const
|
||||||
{
|
{
|
||||||
/* Command doesn't support any parameters. */
|
visibleDesc.add_options()
|
||||||
//TODO Add filter regex #7199
|
("name,n", po::value<std::string>(), "filter by name matches")
|
||||||
|
("type,t", po::value<std::string>(), "filter by type matches");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,8 +88,15 @@ int ObjectListCommand::Run(const boost::program_options::variables_map& vm, cons
|
|||||||
std::map<String, int> type_count;
|
std::map<String, int> type_count;
|
||||||
|
|
||||||
String message;
|
String message;
|
||||||
|
String name_filter, type_filter = "";
|
||||||
|
|
||||||
|
if (vm.count("name"))
|
||||||
|
name_filter = vm["name"].as<std::string>();
|
||||||
|
if (vm.count("type"))
|
||||||
|
type_filter = vm["type"].as<std::string>();
|
||||||
|
|
||||||
while (NetString::ReadStringFromStream(sfp, &message)) {
|
while (NetString::ReadStringFromStream(sfp, &message)) {
|
||||||
ReadObject(message, type_count);
|
ReadObject(message, type_count, name_filter, type_filter);
|
||||||
objects_count++;
|
objects_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,20 +105,23 @@ int ObjectListCommand::Run(const boost::program_options::variables_map& vm, cons
|
|||||||
|
|
||||||
std::cout << FormatTypeCounts(type_count) << std::endl;
|
std::cout << FormatTypeCounts(type_count) << std::endl;
|
||||||
|
|
||||||
Log(LogInformation, "cli", "Found " + Convert::ToString(objects_count) + " objects.");
|
Log(LogInformation, "cli", "Parsed " + Convert::ToString(objects_count) + " objects.");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectListCommand::ReadObject(const String& message, std::map<String, int>& type_count)
|
void ObjectListCommand::ReadObject(const String& message, std::map<String, int>& type_count, String name_filter, String type_filter)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr object = JsonDeserialize(message);
|
Dictionary::Ptr object = JsonDeserialize(message);
|
||||||
|
|
||||||
|
String name = object->Get("name");
|
||||||
String type = object->Get("type");
|
String type = object->Get("type");
|
||||||
|
|
||||||
type_count[type]++;
|
if(!name_filter.IsEmpty() && !Utility::Match(name_filter, name))
|
||||||
|
return;
|
||||||
|
if(!type_filter.IsEmpty() && !Utility::Match(type_filter, type))
|
||||||
|
return;
|
||||||
|
|
||||||
String name = object->Get("name");
|
|
||||||
bool abstract = object->Get("abstract");
|
bool abstract = object->Get("abstract");
|
||||||
Dictionary::Ptr properties = object->Get("properties");
|
Dictionary::Ptr properties = object->Get("properties");
|
||||||
Dictionary::Ptr debug_hints = object->Get("debug_hints");
|
Dictionary::Ptr debug_hints = object->Get("debug_hints");
|
||||||
@ -129,6 +140,7 @@ void ObjectListCommand::ReadObject(const String& message, std::map<String, int>&
|
|||||||
|
|
||||||
std::cout << msgbuf.str() << "\n";
|
std::cout << msgbuf.str() << "\n";
|
||||||
|
|
||||||
|
type_count[type]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ObjectListCommand::FormatProperties(const Dictionary::Ptr& props, const Dictionary::Ptr& debug_hints, int indent)
|
String ObjectListCommand::FormatProperties(const Dictionary::Ptr& props, const Dictionary::Ptr& debug_hints, int indent)
|
||||||
|
@ -46,7 +46,7 @@ public:
|
|||||||
virtual int Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const;
|
virtual int Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void ReadObject(const String& message, std::map<String, int>& type_count);
|
static void ReadObject(const String& message, std::map<String, int>& type_count, String name_filter, String type_filter);
|
||||||
static String FormatProperties(const Dictionary::Ptr& props, const Dictionary::Ptr& debug_hints, int indent = 0);
|
static String FormatProperties(const Dictionary::Ptr& props, const Dictionary::Ptr& debug_hints, int indent = 0);
|
||||||
static String FormatHints(const Dictionary::Ptr& hints, int indent = 0);
|
static String FormatHints(const Dictionary::Ptr& hints, int indent = 0);
|
||||||
static String FormatHint(const Array::Ptr& msg, int indent = 0);
|
static String FormatHint(const Array::Ptr& msg, int indent = 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user