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

Method AddCheckResultLogHistory

lib/db_ido/dbevents.cpp:968–1048  ·  view source on GitHub ↗

logentries */

Source from the content-addressed store, hash-verified

966
967/* logentries */
968void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr &cr)
969{
970 if (!cr)
971 return;
972
973 Dictionary::Ptr varsBefore = cr->GetVarsBefore();
974 Dictionary::Ptr varsAfter = cr->GetVarsAfter();
975
976 if (varsBefore && varsAfter) {
977 if (varsBefore->Get("state") == varsAfter->Get("state") &&
978 varsBefore->Get("state_type") == varsAfter->Get("state_type") &&
979 varsBefore->Get("attempt") == varsAfter->Get("attempt") &&
980 varsBefore->Get("reachable") == varsAfter->Get("reachable"))
981 return; /* Nothing changed, ignore this checkresult. */
982 }
983
984 LogEntryType type;
985 String output = CompatUtility::GetCheckResultOutput(cr);
986
987 Host::Ptr host;
988 Service::Ptr service;
989 tie(host, service) = GetHostService(checkable);
990
991 std::ostringstream msgbuf;
992
993 if (service) {
994 msgbuf << "SERVICE ALERT: "
995 << host->GetName() << ";"
996 << service->GetShortName() << ";"
997 << Service::StateToString(service->GetState()) << ";"
998 << Checkable::StateTypeToString(service->GetStateType()) << ";"
999 << service->GetCheckAttempt() << ";"
1000 << output << ""
1001 << "";
1002
1003 switch (service->GetState()) {
1004 case ServiceOK:
1005 type = LogEntryTypeServiceOk;
1006 break;
1007 case ServiceUnknown:
1008 type = LogEntryTypeServiceUnknown;
1009 break;
1010 case ServiceWarning:
1011 type = LogEntryTypeServiceWarning;
1012 break;
1013 case ServiceCritical:
1014 type = LogEntryTypeServiceCritical;
1015 break;
1016 default:
1017 Log(LogCritical, "DbEvents")
1018 << "Unknown service state: " << service->GetState();
1019 return;
1020 }
1021 } else {
1022 msgbuf << "HOST ALERT: "
1023 << host->GetName() << ";"
1024 << GetHostStateString(host) << ";"
1025 << Checkable::StateTypeToString(host->GetStateType()) << ";"

Callers

nothing calls this directly

Calls 5

LogClass · 0.85
GetMethod · 0.45
GetNameMethod · 0.45
GetStateMethod · 0.45
IsReachableMethod · 0.45

Tested by

no test coverage detected