MCPcopy Create free account
hub / github.com/Icinga/icinga2 / AddCheckableCheckHistory

Method AddCheckableCheckHistory

lib/db_ido/dbevents.cpp:1352–1409  ·  view source on GitHub ↗

servicechecks */

Source from the content-addressed store, hash-verified

1350
1351/* servicechecks */
1352void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
1353{
1354 if (!cr)
1355 return;
1356
1357 Host::Ptr host;
1358 Service::Ptr service;
1359 tie(host, service) = GetHostService(checkable);
1360
1361 DbQuery query1;
1362 query1.Table = service ? "servicechecks" : "hostchecks";
1363 query1.Type = DbQueryInsert;
1364 query1.Category = DbCatCheck;
1365
1366 Dictionary::Ptr fields1 = new Dictionary();
1367 fields1->Set("check_type", !checkable->GetEnableActiveChecks()); /* 0 .. active, 1 .. passive */
1368 fields1->Set("current_check_attempt", checkable->GetCheckAttempt());
1369 fields1->Set("max_check_attempts", checkable->GetMaxCheckAttempts());
1370 fields1->Set("state_type", checkable->GetStateType());
1371
1372 double start = cr->GetExecutionStart();
1373 double end = cr->GetExecutionEnd();
1374 double executionTime = cr->CalculateExecutionTime();
1375
1376 std::pair<unsigned long, unsigned long> timeBagStart = ConvertTimestamp(start);
1377 std::pair<unsigned long, unsigned long> timeBagEnd = ConvertTimestamp(end);
1378
1379 fields1->Set("start_time", DbValue::FromTimestamp(timeBagStart.first));
1380 fields1->Set("start_time_usec", timeBagStart.second);
1381 fields1->Set("end_time", DbValue::FromTimestamp(timeBagEnd.first));
1382 fields1->Set("end_time_usec", timeBagEnd.second);
1383 fields1->Set("command_object_id", checkable->GetCheckCommand());
1384 fields1->Set("execution_time", executionTime);
1385 fields1->Set("latency", cr->CalculateLatency());
1386 fields1->Set("return_code", cr->GetExitStatus());
1387 fields1->Set("perfdata", PluginUtility::FormatPerfdata(cr->GetPerformanceData()));
1388
1389 fields1->Set("output", CompatUtility::GetCheckResultOutput(cr));
1390 fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
1391 fields1->Set("command_line", CompatUtility::GetCommandLine(checkable->GetCheckCommand()));
1392 fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
1393
1394 if (service) {
1395 fields1->Set("service_object_id", service);
1396 fields1->Set("state", service->GetState());
1397 } else {
1398 fields1->Set("host_object_id", host);
1399 fields1->Set("state", GetHostState(host));
1400 }
1401
1402 Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName());
1403
1404 if (endpoint)
1405 fields1->Set("endpoint_object_id", endpoint);
1406
1407 query1.Fields = fields1;
1408 DbObject::OnQuery(query1);
1409}

Callers

nothing calls this directly

Calls 6

GetCheckCommandMethod · 0.80
CalculateLatencyMethod · 0.80
GetNodeNameMethod · 0.80
SetMethod · 0.45
GetStateMethod · 0.45

Tested by

no test coverage detected