xref: /trafficserver/src/traffic_ctl/alarm.cc (revision 4cfd5a73)
1 /** @file
2 
3   traffic_ctl
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 #include "traffic_ctl.h"
25 
26 struct AlarmListPolicy {
27   using entry_type = char *;
28 
29   static void
freeAlarmListPolicy30   free(entry_type e)
31   {
32     TSfree(e);
33   }
34 
35   static entry_type
castAlarmListPolicy36   cast(void *ptr)
37   {
38     return static_cast<entry_type>(ptr);
39   }
40 };
41 
42 using CtrlAlarmList = CtrlMgmtList<AlarmListPolicy>;
43 
44 void
alarm_list()45 CtrlEngine::alarm_list()
46 {
47   TSMgmtError error;
48   CtrlAlarmList alarms;
49 
50   error = TSActiveEventGetMlt(alarms.list);
51   if (error != TS_ERR_OKAY) {
52     CtrlMgmtError(error, "failed to fetch active alarms");
53     status_code = CTRL_EX_ERROR;
54     return;
55   }
56 
57   while (!alarms.empty()) {
58     char *a = alarms.next();
59     std::cout << a << std::endl;
60     TSfree(a);
61   }
62 }
63 
64 void
alarm_clear()65 CtrlEngine::alarm_clear()
66 {
67   TSMgmtError error;
68   CtrlAlarmList alarms;
69 
70   // First get the active alarms ...
71   error = TSActiveEventGetMlt(alarms.list);
72   if (error != TS_ERR_OKAY) {
73     CtrlMgmtError(error, "failed to fetch active alarms");
74     status_code = CTRL_EX_ERROR;
75     return;
76   }
77 
78   // Now resolve them all ...
79   while (!alarms.empty()) {
80     char *a = alarms.next();
81 
82     error = TSEventResolve(a);
83     if (error != TS_ERR_OKAY) {
84       CtrlMgmtError(error, "failed to resolve %s", a);
85       TSfree(a);
86       status_code = CTRL_EX_ERROR;
87       return;
88     }
89 
90     TSfree(a);
91   }
92 }
93 
94 void
alarm_resolve()95 CtrlEngine::alarm_resolve()
96 {
97   TSMgmtError error;
98   CtrlAlarmList alarms;
99 
100   for (const auto &it : arguments.get("resolve")) {
101     error = TSEventResolve(it.c_str());
102     if (error != TS_ERR_OKAY) {
103       CtrlMgmtError(error, "failed to resolve %s", it.c_str());
104       status_code = CTRL_EX_ERROR;
105       return;
106     }
107   }
108 }
109