1 22 package org.jboss.monitor.alarm; 23 24 import java.util.HashMap ; 25 import java.util.Map ; 26 27 33 public class AlarmHelper implements Alarm 34 { 35 37 40 private AlarmHelper() 41 { 42 } 44 45 47 50 public static String getSeverityAsString(int severity) 51 { 52 if (severity < SEVERITY_NORMAL || severity > SEVERITY_UNKNOWN) 53 { 54 severity = SEVERITY_UNKNOWN; 55 } 56 return SEVERITY_STRINGS[severity]; 57 } 58 59 62 public static String getStateAsString(int alarmState) 63 { 64 if (alarmState < STATE_CLEARED || alarmState > STATE_NONE) 65 { 66 alarmState = STATE_NONE; 67 } 68 return STATE_STRINGS[alarmState]; 69 } 70 71 public static Map getAlarmTableNotificationStats(AlarmTableNotification[] almtab) 72 { 73 int stateCleared = 0; 75 int stateChanged = 0; 76 int stateCreated = 0; 77 int stateNone = 0; 78 79 int severityNormal = 0; 80 int severityWarning = 0; 81 int severityMinor = 0; 82 int severityMajor = 0; 83 int severityCritical = 0; 84 int severityUnknown = 0; 85 86 if (almtab != null) 87 { 88 for (int i = 0; i < almtab.length; i++) 89 { 90 AlarmTableNotification atn = almtab[i]; 91 switch (atn.getAlarmState()) 92 { 93 case STATE_CLEARED: 94 ++stateCleared; 95 break; 96 case STATE_CHANGED: 97 ++stateChanged; 98 break; 99 case STATE_CREATED: 100 ++stateCreated; 101 break; 102 case STATE_NONE: 103 default: 104 ++stateNone; 105 break; 106 } 107 switch (atn.getSeverity()) 108 { 109 case SEVERITY_NORMAL: 110 ++severityNormal; 111 break; 112 case SEVERITY_WARNING: 113 ++severityWarning; 114 break; 115 case SEVERITY_MINOR: 116 ++severityMinor; 117 break; 118 case SEVERITY_MAJOR: 119 ++severityMajor; 120 break; 121 case SEVERITY_CRITICAL: 122 ++severityCritical; 123 break; 124 case SEVERITY_UNKNOWN: 125 default: 126 ++severityUnknown; 127 break; 128 } 129 } 130 Map stats = new HashMap (); 131 132 stats.put(getSeverityAsString(SEVERITY_NORMAL), new Integer (severityNormal)); 133 stats.put(getSeverityAsString(SEVERITY_WARNING), new Integer (severityWarning)); 134 stats.put(getSeverityAsString(SEVERITY_MINOR), new Integer (severityMinor)); 135 stats.put(getSeverityAsString(SEVERITY_MAJOR), new Integer (severityMajor)); 136 stats.put(getSeverityAsString(SEVERITY_CRITICAL), new Integer (severityCritical)); 137 stats.put(getSeverityAsString(SEVERITY_UNKNOWN), new Integer (severityUnknown)); 138 139 stats.put(getStateAsString(STATE_CLEARED), new Integer (stateCleared)); 140 stats.put(getStateAsString(STATE_CHANGED), new Integer (stateChanged)); 141 stats.put(getStateAsString(STATE_CREATED), new Integer (stateCreated)); 142 stats.put(getStateAsString(STATE_NONE), new Integer (stateNone)); 143 144 return stats; 145 } 146 else 147 { 148 return null; 149 } 150 } 151 } 152 | Popular Tags |