Update livestatus and statusdata to properly support booleans

fixes #8100
This commit is contained in:
Gunnar Beutner 2014-12-17 08:54:28 +01:00
parent 5dd0bbfe31
commit 9eeb64a780
6 changed files with 20 additions and 4 deletions

View File

@ -59,6 +59,11 @@ public:
} }
} }
static inline long ToLong(const Value& val)
{
return val;
}
static inline double ToDouble(const Value& val) static inline double ToDouble(const Value& val)
{ {
return val; return val;

View File

@ -34,6 +34,11 @@ Value::operator double(void) const
if (value) if (value)
return *value; return *value;
const bool *fvalue = boost::get<bool>(&m_Value);
if (fvalue)
return *fvalue;
if (IsEmpty()) if (IsEmpty())
return 0; return 0;
@ -72,7 +77,11 @@ Value::operator String(void) const
std::ostream& icinga::operator<<(std::ostream& stream, const Value& value) std::ostream& icinga::operator<<(std::ostream& stream, const Value& value)
{ {
stream << static_cast<String>(value); if (value.IsBoolean())
stream << static_cast<int>(value);
else
stream << static_cast<String>(value);
return stream; return stream;
} }

View File

@ -522,7 +522,7 @@ void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const CustomVarObj
if (kv.first.IsEmpty()) if (kv.first.IsEmpty())
continue; continue;
String value; Value value;
if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>()) { if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>()) {
value = JsonEncode(kv.second); value = JsonEncode(kv.second);

View File

@ -573,7 +573,7 @@ bool IdoMysqlConnection::FieldToEscapedString(const String& key, const Value& va
Value fvalue; Value fvalue;
if (rawvalue.IsBoolean()) if (rawvalue.IsBoolean())
fvalue = rawvalue.ToBool() ? 1 : 0; fvalue = Convert::ToLong(rawvalue);
else else
fvalue = rawvalue; fvalue = rawvalue;

View File

@ -567,7 +567,7 @@ bool IdoPgsqlConnection::FieldToEscapedString(const String& key, const Value& va
Value fvalue; Value fvalue;
if (rawvalue.IsBoolean()) if (rawvalue.IsBoolean())
fvalue = rawvalue.ToBool() ? 1 : 0; fvalue = Convert::ToLong(rawvalue);
else else
fvalue = rawvalue; fvalue = rawvalue;

View File

@ -446,6 +446,8 @@ void LivestatusQuery::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, i
if (value.IsObjectType<Array>()) if (value.IsObjectType<Array>())
PrintCsvArray(fp, value, level + 1); PrintCsvArray(fp, value, level + 1);
else if (value.IsBoolean())
fp << Convert::ToLong(value);
else else
fp << value; fp << value;
} }