| 1966 | } |
| 1967 | |
| 1968 | void IcingaDB::SendSentNotification( |
| 1969 | const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set<User::Ptr>& users, |
| 1970 | NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text, double sendTime |
| 1971 | ) |
| 1972 | { |
| 1973 | if (!GetActive()) { |
| 1974 | return; |
| 1975 | } |
| 1976 | |
| 1977 | Host::Ptr host; |
| 1978 | Service::Ptr service; |
| 1979 | tie(host, service) = GetHostService(checkable); |
| 1980 | |
| 1981 | auto finalText = text; |
| 1982 | if (finalText == "" && cr) { |
| 1983 | finalText = cr->GetOutput(); |
| 1984 | } |
| 1985 | |
| 1986 | auto usersAmount (users.size()); |
| 1987 | auto sendTs (TimestampToMilliseconds(sendTime)); |
| 1988 | |
| 1989 | auto notificationTypeStr(GetNotificationTypeByEnum(type)); |
| 1990 | Array::Ptr rawId = new Array({m_EnvironmentId, notification->GetName()}); |
| 1991 | rawId->Add(notificationTypeStr); |
| 1992 | rawId->Add(sendTs); |
| 1993 | |
| 1994 | auto notificationHistoryId (HashValue(rawId)); |
| 1995 | |
| 1996 | int state{}; |
| 1997 | if (!cr) { |
| 1998 | state = ServicePending; |
| 1999 | } else if (service) { |
| 2000 | state = cr->GetState(); |
| 2001 | } else { |
| 2002 | state = Host::CalculateState(cr->GetState()); |
| 2003 | } |
| 2004 | |
| 2005 | int previous_hard_state{}; |
| 2006 | if (!cr) { |
| 2007 | previous_hard_state = ServicePending; |
| 2008 | } else if (service) { |
| 2009 | previous_hard_state = cr->GetPreviousHardState(); |
| 2010 | } else { |
| 2011 | previous_hard_state = Host::CalculateState(cr->GetPreviousHardState()); |
| 2012 | } |
| 2013 | |
| 2014 | RedisConnection::Query xAdd ({ |
| 2015 | "XADD", "icinga:history:stream:notification", "*", |
| 2016 | "id", notificationHistoryId, |
| 2017 | "environment_id", m_EnvironmentId, |
| 2018 | "notification_id", GetObjectIdentifier(notification), |
| 2019 | "host_id", GetObjectIdentifier(host), |
| 2020 | "type", notificationTypeStr, |
| 2021 | "state", Convert::ToString(state), |
| 2022 | "previous_hard_state", Convert::ToString(previous_hard_state), |
| 2023 | "author", Utility::ValidateUTF8(author), |
| 2024 | "text", Utility::ValidateUTF8(finalText), |
| 2025 | "users_notified", Convert::ToString(usersAmount), |
no test coverage detected