mirror of https://github.com/Icinga/icinga2.git
parent
d500097e4b
commit
ea24147d0d
|
@ -697,6 +697,55 @@ void Utility::QueueAsyncCallback(const boost::function<void (void)>& callback)
|
||||||
Application::GetTP().Post(callback);
|
Application::GetTP().Post(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String Utility::NaturalJoin(const std::vector<String>& tokens)
|
||||||
|
{
|
||||||
|
String result;
|
||||||
|
|
||||||
|
for (int i = 0; i < tokens.size(); i++) {
|
||||||
|
result += tokens[i];
|
||||||
|
|
||||||
|
if (tokens.size() > i + 1) {
|
||||||
|
if (i < tokens.size() - 2)
|
||||||
|
result += ", ";
|
||||||
|
else if (i == tokens.size() - 2)
|
||||||
|
result += " and ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
String Utility::FormatDuration(int duration)
|
||||||
|
{
|
||||||
|
std::vector<String> tokens;
|
||||||
|
String result;
|
||||||
|
|
||||||
|
if (duration >= 86400) {
|
||||||
|
int days = duration / 86400;
|
||||||
|
tokens.push_back(Convert::ToString(days) + (days != 1 ? " days" : " day"));
|
||||||
|
duration %= 86400;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (duration >= 3600) {
|
||||||
|
int hours = duration / 3600;
|
||||||
|
tokens.push_back(Convert::ToString(hours) + (hours != 1 ? " hours" : " hour"));
|
||||||
|
duration %= 3600;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (duration >= 60) {
|
||||||
|
int minutes = duration / 60;
|
||||||
|
tokens.push_back(Convert::ToString(minutes) + (minutes != 1 ? " minutes" : " minute"));
|
||||||
|
duration %= 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (duration >= 1) {
|
||||||
|
int seconds = duration;
|
||||||
|
tokens.push_back(Convert::ToString(seconds) + (seconds != 1 ? " seconds" : " second"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return NaturalJoin(tokens);
|
||||||
|
}
|
||||||
|
|
||||||
String Utility::FormatDateTime(const char *format, double ts)
|
String Utility::FormatDateTime(const char *format, double ts)
|
||||||
{
|
{
|
||||||
char timestamp[128];
|
char timestamp[128];
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
#include <boost/thread/tss.hpp>
|
#include <boost/thread/tss.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
@ -83,6 +84,9 @@ public:
|
||||||
|
|
||||||
static void QueueAsyncCallback(const boost::function<void (void)>& callback);
|
static void QueueAsyncCallback(const boost::function<void (void)>& callback);
|
||||||
|
|
||||||
|
static String NaturalJoin(const std::vector<String>& tokens);
|
||||||
|
|
||||||
|
static String FormatDuration(int duration);
|
||||||
static String FormatDateTime(const char *format, double ts);
|
static String FormatDateTime(const char *format, double ts);
|
||||||
|
|
||||||
static
|
static
|
||||||
|
|
|
@ -70,6 +70,9 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResul
|
||||||
perfdata->Set("num_services_in_downtime", ss.services_in_downtime);
|
perfdata->Set("num_services_in_downtime", ss.services_in_downtime);
|
||||||
perfdata->Set("num_services_acknowledged", ss.services_acknowledged);
|
perfdata->Set("num_services_acknowledged", ss.services_acknowledged);
|
||||||
|
|
||||||
|
double uptime = Utility::GetTime() - Application::GetStartTime();
|
||||||
|
perfdata->Set("uptime", uptime);
|
||||||
|
|
||||||
HostStatistics hs = CIB::CalculateHostStats();
|
HostStatistics hs = CIB::CalculateHostStats();
|
||||||
|
|
||||||
perfdata->Set("num_hosts_up", hs.hosts_up);
|
perfdata->Set("num_hosts_up", hs.hosts_up);
|
||||||
|
@ -79,7 +82,8 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResul
|
||||||
perfdata->Set("num_hosts_in_downtime", hs.hosts_in_downtime);
|
perfdata->Set("num_hosts_in_downtime", hs.hosts_in_downtime);
|
||||||
perfdata->Set("num_hosts_acknowledged", hs.hosts_acknowledged);
|
perfdata->Set("num_hosts_acknowledged", hs.hosts_acknowledged);
|
||||||
|
|
||||||
cr->SetOutput("Icinga 2 is running. Version: " + Application::GetVersion());
|
cr->SetOutput("Icinga 2 has been running for " + Utility::FormatDuration(uptime) +
|
||||||
|
". Version: " + Application::GetVersion());
|
||||||
cr->SetPerformanceData(perfdata);
|
cr->SetPerformanceData(perfdata);
|
||||||
cr->SetState(ServiceOK);
|
cr->SetState(ServiceOK);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue