2013-11-12 12:04:52 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2014-03-19 01:02:29 +01:00
|
|
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
2013-11-12 12:04:52 +01:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "methods/icingachecktask.hpp"
|
|
|
|
#include "icinga/cib.hpp"
|
|
|
|
#include "icinga/service.hpp"
|
|
|
|
#include "icinga/icingaapplication.hpp"
|
2014-09-17 15:38:39 +02:00
|
|
|
#include "icinga/perfdatavalue.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/application.hpp"
|
|
|
|
#include "base/objectlock.hpp"
|
|
|
|
#include "base/utility.hpp"
|
|
|
|
#include "base/scriptfunction.hpp"
|
|
|
|
#include "base/dynamictype.hpp"
|
2013-11-12 12:04:52 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
REGISTER_SCRIPTFUNCTION(IcingaCheck, &IcingaCheckTask::ScriptFunc);
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr)
|
2013-11-12 12:04:52 +01:00
|
|
|
{
|
|
|
|
double interval = Utility::GetTime() - Application::GetStartTime();
|
|
|
|
|
|
|
|
if (interval > 60)
|
|
|
|
interval = 60;
|
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
Array::Ptr perfdata = make_shared<Array>();
|
|
|
|
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("active_host_checks", CIB::GetActiveHostChecksStatistics(interval) / interval));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("passive_host_checks", CIB::GetPassiveHostChecksStatistics(interval) / interval));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("active_host_checks_1min", CIB::GetActiveHostChecksStatistics(60)));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("passive_host_checks_1min", CIB::GetPassiveHostChecksStatistics(60)));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("active_host_checks_5min", CIB::GetActiveHostChecksStatistics(60 * 5)));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("passive_host_checks_5min", CIB::GetPassiveHostChecksStatistics(60 * 5)));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("active_host_checks_15min", CIB::GetActiveHostChecksStatistics(60 * 15)));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("passive_host_checks_15min", CIB::GetPassiveHostChecksStatistics(60 * 15)));
|
|
|
|
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("active_service_checks", CIB::GetActiveServiceChecksStatistics(interval) / interval));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("passive_service_checks", CIB::GetPassiveServiceChecksStatistics(interval) / interval));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("active_service_checks_1min", CIB::GetActiveServiceChecksStatistics(60)));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("passive_service_checks_1min", CIB::GetPassiveServiceChecksStatistics(60)));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("active_service_checks_5min", CIB::GetActiveServiceChecksStatistics(60 * 5)));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("passive_service_checks_5min", CIB::GetPassiveServiceChecksStatistics(60 * 5)));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("active_service_checks_15min", CIB::GetActiveServiceChecksStatistics(60 * 15)));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("passive_service_checks_15min", CIB::GetPassiveServiceChecksStatistics(60 * 15)));
|
2014-05-26 20:56:34 +02:00
|
|
|
|
|
|
|
CheckableCheckStatistics scs = CIB::CalculateServiceCheckStats();
|
2014-02-10 14:56:39 +01:00
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
perfdata->Add(make_shared<PerfdataValue>("min_latency", scs.min_latency));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("max_latency", scs.max_latency));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("avg_latency", scs.avg_latency));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("min_execution_time", scs.min_latency));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("max_execution_time", scs.max_latency));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("avg_execution_time", scs.avg_execution_time));
|
2014-02-10 14:56:39 +01:00
|
|
|
|
|
|
|
ServiceStatistics ss = CIB::CalculateServiceStats();
|
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_services_ok", ss.services_ok));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_services_warning", ss.services_warning));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_services_critical", ss.services_critical));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_services_unknown", ss.services_unknown));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_services_pending", ss.services_pending));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_services_unreachable", ss.services_unreachable));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_services_flapping", ss.services_flapping));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_services_in_downtime", ss.services_in_downtime));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_services_acknowledged", ss.services_acknowledged));
|
2014-02-10 14:56:39 +01:00
|
|
|
|
2014-04-28 09:16:27 +02:00
|
|
|
double uptime = Utility::GetTime() - Application::GetStartTime();
|
2014-09-17 15:38:39 +02:00
|
|
|
perfdata->Add(make_shared<PerfdataValue>("uptime", uptime));
|
2014-04-28 09:16:27 +02:00
|
|
|
|
2014-02-10 14:56:39 +01:00
|
|
|
HostStatistics hs = CIB::CalculateHostStats();
|
|
|
|
|
2014-09-17 15:38:39 +02:00
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_hosts_up", hs.hosts_up));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_hosts_down", hs.hosts_down));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_hosts_unreachable", hs.hosts_unreachable));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_hosts_flapping", hs.hosts_flapping));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_hosts_in_downtime", hs.hosts_in_downtime));
|
|
|
|
perfdata->Add(make_shared<PerfdataValue>("num_hosts_acknowledged", hs.hosts_acknowledged));
|
2013-12-13 15:09:17 +01:00
|
|
|
|
2014-04-28 09:16:27 +02:00
|
|
|
cr->SetOutput("Icinga 2 has been running for " + Utility::FormatDuration(uptime) +
|
|
|
|
". Version: " + Application::GetVersion());
|
2013-11-12 12:04:52 +01:00
|
|
|
cr->SetPerformanceData(perfdata);
|
2014-04-08 09:11:54 +02:00
|
|
|
cr->SetState(ServiceOK);
|
2013-11-12 12:04:52 +01:00
|
|
|
|
2014-03-12 10:05:36 +01:00
|
|
|
service->ProcessCheckResult(cr);
|
2013-11-12 12:04:52 +01:00
|
|
|
}
|
|
|
|
|