return val;
}
+String Convert::ToString(double val)
+{
+ std::ostringstream msgbuf;
+ msgbuf << std::fixed << val;
+ return msgbuf.str();
+}
+
double Convert::ToDateTimeValue(double val)
{
return val;
static String ToString(const String& val);
static String ToString(const Value& val);
+ static String ToString(double val);
static double ToDateTimeValue(double val);
static double ToDateTimeValue(const Value& val);
static String NumberToString(void)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
- double self = vframe->Self;
- return Convert::ToString(self);
+ return vframe->Self;
}
Object::Ptr Number::GetPrototype(void)
Value::operator String(void) const
{
Object *object;
- double integral, fractional;
+ double dvalue, integral, fractional;
switch (GetType()) {
case ValueEmpty:
return String();
case ValueNumber:
- fractional = std::modf(boost::get<double>(m_Value), &integral);
+ dvalue = boost::get<double>(m_Value);
+ fractional = std::modf(dvalue, &integral);
if (fractional != 0)
- return boost::lexical_cast<std::string>(m_Value);
+ return Convert::ToString(dvalue);
else
- return boost::lexical_cast<std::string>((long)integral);
+ return Convert::ToString(static_cast<long>(dvalue));
case ValueBoolean:
if (boost::get<bool>(m_Value))
return "true";
*result = StateToString(GetState());
return true;
} else if (macro == "state_id") {
- *result = Convert::ToString(GetState());
+ *result = GetState();
return true;
} else if (macro == "state_type") {
*result = StateTypeToString(GetStateType());
*result = StateToString(GetLastState());
return true;
} else if (macro == "last_state_id") {
- *result = Convert::ToString(GetLastState());
+ *result = GetLastState();
return true;
} else if (macro == "last_state_type") {
*result = StateTypeToString(GetLastStateType());
return true;
} else if (macro == "last_state_change") {
- *result = Convert::ToString((long)GetLastStateChange());
+ *result = GetLastStateChange();
return true;
} else if (macro == "downtime_depth") {
- *result = Convert::ToString((long)GetDowntimeDepth());
+ *result = GetDowntimeDepth();
return true;
} else if (macro == "duration_sec") {
- *result = Convert::ToString((long)(Utility::GetTime() - GetLastStateChange()));
+ *result = Utility::GetTime() - GetLastStateChange();
return true;
} else if (macro == "num_services" || macro == "num_services_ok" || macro == "num_services_warning"
|| macro == "num_services_unknown" || macro == "num_services_critical") {
count++;
}
- *result = Convert::ToString(count);
+ *result = count;
return true;
}
if (cr) {
if (macro == "latency") {
- *result = Convert::ToString(cr->CalculateLatency());
+ *result = cr->CalculateLatency();
return true;
} else if (macro == "execution_time") {
- *result = Convert::ToString(cr->CalculateExecutionTime());
+ *result = cr->CalculateExecutionTime();
return true;
} else if (macro == "output") {
*result = cr->GetOutput();
*result = PluginUtility::FormatPerfdata(cr->GetPerformanceData());
return true;
} else if (macro == "last_check") {
- *result = Convert::ToString((long)cr->GetScheduleStart());
+ *result = cr->GetScheduleStart();
return true;
} else if (macro == "check_source") {
*result = cr->GetCheckSource();
double now = Utility::GetTime();
if (macro == "timet") {
- *result = Convert::ToString((long)now);
+ *result = now;
return true;
} else if (macro == "long_date_time") {
*result = Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", now);
ServiceStatistics ss = CIB::CalculateServiceStats();
if (macro == "num_services_ok") {
- *result = Convert::ToString(ss.services_ok);
+ *result = ss.services_ok;
return true;
} else if (macro == "num_services_warning") {
- *result = Convert::ToString(ss.services_warning);
+ *result = ss.services_warning;
return true;
} else if (macro == "num_services_critical") {
- *result = Convert::ToString(ss.services_critical);
+ *result = ss.services_critical;
return true;
} else if (macro == "num_services_unknown") {
- *result = Convert::ToString(ss.services_unknown);
+ *result = ss.services_unknown;
return true;
} else if (macro == "num_services_pending") {
- *result = Convert::ToString(ss.services_pending);
+ *result = ss.services_pending;
return true;
} else if (macro == "num_services_unreachable") {
- *result = Convert::ToString(ss.services_unreachable);
+ *result = ss.services_unreachable;
return true;
} else if (macro == "num_services_flapping") {
- *result = Convert::ToString(ss.services_flapping);
+ *result = ss.services_flapping;
return true;
} else if (macro == "num_services_in_downtime") {
- *result = Convert::ToString(ss.services_in_downtime);
+ *result = ss.services_in_downtime;
return true;
} else if (macro == "num_services_acknowledged") {
- *result = Convert::ToString(ss.services_acknowledged);
+ *result = ss.services_acknowledged;
return true;
}
}
HostStatistics hs = CIB::CalculateHostStats();
if (macro == "num_hosts_up") {
- *result = Convert::ToString(hs.hosts_up);
+ *result = hs.hosts_up;
return true;
} else if (macro == "num_hosts_down") {
- *result = Convert::ToString(hs.hosts_down);
+ *result = hs.hosts_down;
return true;
} else if (macro == "num_hosts_pending") {
- *result = Convert::ToString(hs.hosts_pending);
+ *result = hs.hosts_pending;
return true;
} else if (macro == "num_hosts_unreachable") {
- *result = Convert::ToString(hs.hosts_unreachable);
+ *result = hs.hosts_unreachable;
return true;
} else if (macro == "num_hosts_flapping") {
- *result = Convert::ToString(hs.hosts_flapping);
+ *result = hs.hosts_flapping;
return true;
} else if (macro == "num_hosts_in_downtime") {
- *result = Convert::ToString(hs.hosts_in_downtime);
+ *result = hs.hosts_in_downtime;
return true;
} else if (macro == "num_hosts_acknowledged") {
- *result = Convert::ToString(hs.hosts_acknowledged);
+ *result = hs.hosts_acknowledged;
return true;
}
}
*result = StateToString(GetState());
return true;
} else if (macro == "state_id") {
- *result = Convert::ToString(GetState());
+ *result = GetState();
return true;
} else if (macro == "state_type") {
*result = StateTypeToString(GetStateType());
*result = StateToString(GetLastState());
return true;
} else if (macro == "last_state_id") {
- *result = Convert::ToString(GetLastState());
+ *result = GetLastState();
return true;
} else if (macro == "last_state_type") {
*result = StateTypeToString(GetLastStateType());
return true;
} else if (macro == "last_state_change") {
- *result = Convert::ToString((long)GetLastStateChange());
+ *result = GetLastStateChange();
return true;
} else if (macro == "downtime_depth") {
- *result = Convert::ToString((long)GetDowntimeDepth());
+ *result = GetDowntimeDepth();
return true;
} else if (macro == "duration_sec") {
- *result = Convert::ToString((long)(Utility::GetTime() - GetLastStateChange()));
+ *result = Utility::GetTime() - GetLastStateChange();
return true;
}
if (cr) {
if (macro == "latency") {
- *result = Convert::ToString(cr->CalculateLatency());
+ *result = cr->CalculateLatency();
return true;
} else if (macro == "execution_time") {
- *result = Convert::ToString(cr->CalculateExecutionTime());
+ *result = cr->CalculateExecutionTime();
return true;
} else if (macro == "output") {
*result = cr->GetOutput();
*result = PluginUtility::FormatPerfdata(cr->GetPerformanceData());
return true;
} else if (macro == "last_check") {
- *result = Convert::ToString((long)cr->GetExecutionEnd());
+ *result = cr->GetExecutionEnd();
return true;
} else if (macro == "check_source") {
*result = cr->GetCheckSource();