blob: 578cee95b79e9d41b571af4cb78873ec9b6d9278 [file] [log] [blame]
kmcpeakeb172d5f2015-12-10 11:30:43 +00001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
kmcpeakeb172d5f2015-12-10 11:30:43 +00003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.faultmanagement.alarms.cli;
17
18import java.util.Map;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
22import org.onosproject.incubator.net.faultmanagement.alarm.AlarmService;
23
24/**
25 * Lists alarm counts across all devices.
26 */
27@Command(scope = "onos", name = "alarm-counts",
28 description = "Lists alarm counts across all devices.")
29public class GetAllAlarmsCounts extends AbstractShellCommand {
30
31 @Override
32 protected void execute() {
33 Map<Alarm.SeverityLevel, Long> alarmCounts
34 = AbstractShellCommand.get(AlarmService.class).getAlarmCounts();
35 printCounts(alarmCounts);
36 }
37
Andrea Campanellae72ac552016-04-11 10:04:52 -070038 void printCounts(Map<Alarm.SeverityLevel, Long> alarmCounts) {
kmcpeakeb172d5f2015-12-10 11:30:43 +000039 alarmCounts.entrySet().stream().forEach((countEntry) -> {
Andrea Campanellae72ac552016-04-11 10:04:52 -070040 print(String.format("%s, %d",
kmcpeakeb172d5f2015-12-10 11:30:43 +000041 countEntry.getKey(), countEntry.getValue()));
42
43 });
44 }
45}