mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-22 13:14:32 +02:00
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
|
else
|
||||||
fp << ";";
|
fp << ";";
|
||||||
|
|
||||||
if (value.IsObjectType<Array>()) {
|
if (value.IsObjectType<Array>())
|
||||||
bool first_inner = true;
|
PrintCsvArray(fp, value, 0);
|
||||||
Array::Ptr arr = static_cast<Array::Ptr>(value);
|
else
|
||||||
|
|
||||||
ObjectLock rlock(arr);
|
|
||||||
BOOST_FOREACH(const Value& arr_val, arr) {
|
|
||||||
if (first_inner)
|
|
||||||
first_inner = false;
|
|
||||||
else
|
|
||||||
fp << ",";
|
|
||||||
|
|
||||||
fp << Convert::ToString(arr_val);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fp << Convert::ToString(value);
|
fp << Convert::ToString(value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fp << "\n";
|
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)
|
void Query::ExecuteGetHelper(const Stream::Ptr& stream)
|
||||||
{
|
{
|
||||||
Log(LogInformation, "livestatus", "Table: " + m_Table);
|
Log(LogInformation, "livestatus", "Table: " + m_Table);
|
||||||
|
@ -77,6 +77,7 @@ private:
|
|||||||
String m_ErrorMessage;
|
String m_ErrorMessage;
|
||||||
|
|
||||||
void PrintResultSet(std::ostream& fp, const std::vector<String>& columns, const Array::Ptr& rs);
|
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 ExecuteGetHelper(const Stream::Ptr& stream);
|
||||||
void ExecuteCommandHelper(const Stream::Ptr& stream);
|
void ExecuteCommandHelper(const Stream::Ptr& stream);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user