]> granicus.if.org Git - icinga2/blob - test/icinga-notification.cpp
Implement WorkQueue metric stats and periodic logging
[icinga2] / test / icinga-notification.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/)  *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #include "icinga/notification.hpp"
21 #include <BoostTestTargetConfig.h>
22
23 using namespace icinga;
24
25 BOOST_AUTO_TEST_SUITE(icinga_notification)
26
27 BOOST_AUTO_TEST_CASE(state_filter)
28 {
29         unsigned long fstate;
30
31         Array::Ptr states = new Array();
32         states->Add("OK");
33         states->Add("Warning");
34
35         Notification::Ptr notification = new Notification();
36
37         notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
38         notification->Activate();
39         notification->SetAuthority(true);
40
41         /* Test passing notification state */
42         fstate = StateFilterWarning;
43         std::cout << "#1 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass. " << std::endl;
44         BOOST_CHECK(notification->GetStateFilter() & fstate);
45
46         /* Test filtered notification state */
47         fstate = StateFilterUnknown;
48         std::cout << "#2 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
49         BOOST_CHECK(!(notification->GetStateFilter() & fstate));
50
51         /* Test unset states filter configuration */
52         notification->SetStateFilter(FilterArrayToInt(Array::Ptr(), notification->GetStateFilterMap(), ~0));
53
54         fstate = StateFilterOK;
55         std::cout << "#3 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass." << std::endl;
56         BOOST_CHECK(notification->GetStateFilter() & fstate);
57
58         /* Test empty states filter configuration */
59         states->Clear();
60         notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
61
62         fstate = StateFilterCritical;
63         std::cout << "#4 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
64         BOOST_CHECK(!(notification->GetStateFilter() & fstate));
65 }
66 BOOST_AUTO_TEST_CASE(type_filter)
67 {
68         unsigned long ftype;
69
70         Array::Ptr types = new Array();
71         types->Add("Problem");
72         types->Add("DowntimeStart");
73         types->Add("DowntimeEnd");
74
75         Notification::Ptr notification = new Notification();
76
77         notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
78         notification->Activate();
79         notification->SetAuthority(true);
80
81         /* Test passing notification type */
82         ftype = NotificationProblem;
83         std::cout << "#1 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
84         BOOST_CHECK(notification->GetTypeFilter() & ftype);
85
86         /* Test filtered notification type */
87         ftype = NotificationCustom;
88         std::cout << "#2 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
89         BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
90
91         /* Test unset types filter configuration */
92         notification->SetTypeFilter(FilterArrayToInt(Array::Ptr(), notification->GetTypeFilterMap(), ~0));
93
94         ftype = NotificationRecovery;
95         std::cout << "#3 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
96         BOOST_CHECK(notification->GetTypeFilter() & ftype);
97
98         /* Test empty types filter configuration */
99         types->Clear();
100         notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
101
102         ftype = NotificationProblem;
103         std::cout << "#4 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
104         BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
105 }
106 BOOST_AUTO_TEST_SUITE_END()