mirror of https://github.com/Icinga/icinga2.git
livestatus: add array delimiter based on level for csv output
... 0 uses comma, 1 uses the pipe for csv output. for json we do not make any difference. fixes #4412
This commit is contained in:
parent
e81fd48bbd
commit
42dcd854fb
|
@ -287,22 +287,10 @@ void Query::PrintResultSet(std::ostream& fp, const std::vector<String>& columns,
|
|||
else
|
||||
fp << ";";
|
||||
|
||||
if (value.IsObjectType<Array>()) {
|
||||
bool first_inner = true;
|
||||
Array::Ptr arr = static_cast<Array::Ptr>(value);
|
||||
|
||||
ObjectLock rlock(arr);
|
||||
BOOST_FOREACH(const Value& arr_val, arr) {
|
||||
if (first_inner)
|
||||
first_inner = false;
|
||||
else
|
||||
fp << ",";
|
||||
|
||||
fp << Convert::ToString(arr_val);
|
||||
}
|
||||
} else {
|
||||
if (value.IsObjectType<Array>())
|
||||
PrintCsvArray(fp, value, 0);
|
||||
else
|
||||
fp << Convert::ToString(value);
|
||||
}
|
||||
}
|
||||
|
||||
fp << "\n";
|
||||
|
@ -312,6 +300,24 @@ void Query::PrintResultSet(std::ostream& fp, const std::vector<String>& columns,
|
|||
}
|
||||
}
|
||||
|
||||
void Query::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level)
|
||||
{
|
||||
bool first = true;
|
||||
|
||||
ObjectLock olock(array);
|
||||
BOOST_FOREACH(const Value& value, array) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
fp << ((level == 0) ? "," : "|");
|
||||
|
||||
if (value.IsObjectType<Array>())
|
||||
PrintCsvArray(fp, value, level + 1);
|
||||
else
|
||||
fp << Convert::ToString(value);
|
||||
}
|
||||
}
|
||||
|
||||
void Query::ExecuteGetHelper(const Stream::Ptr& stream)
|
||||
{
|
||||
Log(LogInformation, "livestatus", "Table: " + m_Table);
|
||||
|
|
|
@ -77,6 +77,7 @@ private:
|
|||
String m_ErrorMessage;
|
||||
|
||||
void PrintResultSet(std::ostream& fp, const std::vector<String>& columns, const Array::Ptr& rs);
|
||||
void PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level);
|
||||
|
||||
void ExecuteGetHelper(const Stream::Ptr& stream);
|
||||
void ExecuteCommandHelper(const Stream::Ptr& stream);
|
||||
|
|
Loading…
Reference in New Issue