def alarmdAlarms(self): # First check if the alarmd is terminated alarmdStatus = Nodes.present(self.mgmt, '/pm/monitor/process/alarmd/state') if alarmdStatus != 'running': self.xmlError('', 'the alarm service is not running.') return # slashes are escaped in this list alarmNames = Nodes.getMgmtLocalChildrenNames(self.mgmt, '/alarm/state/alarm') # avoid the appliance and group healths alarmNames = [name for name in alarmNames if not (name.startswith('app:') or name.startswith('group:'))] alarmsRaw = self.mgmt.getPattern(*['/alarm/state/alarm/%s/*' % name for name in alarmNames]) # build the alarm table (with unescaped slashes) alarms = {} for k, v in alarmsRaw.iteritems(): name, entry = re_alarmSplit.match(k).groups() name = name.replace('\\/', '/') if name not in alarms: alarms[name] = {} alarms[name][entry] = v # Insert an item into a CSV string. # The CSV string is returned alphabetically sorted. def csvInsert(csv, item): if csv: csvList = csv.split(',') csvList.append(item) csvList.sort(FormUtils.alphanumericCompare) csv = ','.join(csvList) else: csv = item return csv # Add in any synthetic alarms. root = alarms['health'] synths = self.getSyntheticAlarms() for k, v in synths.iteritems(): root['aggregates'] = csvInsert(root['aggregates'], k) alarms.update(synths) # Add in any custom trigger notes. notesMap = self._alarmNotesMap.copy() notesMap.update(self.getCustomTriggerMessages()) # get children for this alarm id def getChildren(alarmId): aggs = alarms[alarmId]['aggregates'] if aggs: return aggs.split(',') else: return [] # does this alarm have any non-hidden children? def hasVisibleChildren(alarmId): for ch in getChildren(alarmId): if 'true' != alarms[ch].get('hidden'): return True return False # sort this alarm id's chilren, plop them in def xmlizeChildren(parentEl, alarmId): children = getChildren(alarmId) children.sort(FormUtils.alphanumericCompare, key=lambda a: alarms[a]['display_name']) for ch in children: xmlizeAlarm(parentEl, ch) # xmlize an alarm, and place it in the parent el def xmlizeAlarm(parentEl, alarmId): alarm = alarms[alarmId] # skip it if "hidden" if 'true' == alarm.get('hidden'): return status = 'OK' statusStyle = 'statusSuccess' collapse = alarm['aggregates'] note = False # 'suppressed' == true overrides 'enabled' != true if 'true' == alarm.get('suppressed'): # suppressed: status = 'Suppressed' statusStyle = 'statusDisabled' elif 'true' != alarm.get('enabled'): # not enabled: status = 'Disabled' statusStyle = 'statusDisabled' if 'true' == alarm.get('triggered'): # triggered: status = alarm['severity_str'] if status.lower() == 'status': status = alarm.get('health_note', 'Needs Attention') statusStyle = 'statusFailure' collapse = False note = alarm.get('trigger_reason', '') if alarmId in notesMap: special = notesMap[alarmId] if type(special) is MethodType: note = special(alarm) elif type(special) is FunctionType: note = special(self.mgmt, alarm) elif type(special) is StringType: note = note + special el = self.doc.createElement('alarm') el.setAttribute('id', alarmId) el.setAttribute('prettyName', alarm['display_name']) el.setAttribute('status', status) el.setAttribute('description', alarm['description']) el.setAttribute('statusStyle', statusStyle) el.setAttribute('collapse', collapse and 'true' or 'false') if note: noteEl = self.doc.createElement('triggerMessage') noteEl.setAttribute('hasChildAlarms', hasVisibleChildren(alarmId) and 'true' or 'false') noteEl.appendChild(self.doc.createTextNode(note)) el.appendChild(noteEl) parentEl.appendChild(el) xmlizeChildren(el, alarmId) # the 'health' alarm is a top-level container of all the others # (this may need to be tweaked in the future) alarmsEl = self.doc.createElement('alarms') xmlizeChildren(alarmsEl, 'health') self.doc.documentElement.appendChild(alarmsEl) self.writeXmlDoc()
def tcpDumps(self): # dump capture files table on top if 'removeFiles' in self.fields: self.removeDiagnosticFile() # running tcp dumps table below: elif 'addTcpDump' in self.fields: ifaces = FormUtils.getPrefixedFieldNames('iface_', self.fields) # We need to handle RiOS interfaces and host interfaces (BOB boxes). riosIfaces = [] hostIfaces = [] for iface in ifaces: if iface == 'All': pass elif iface.startswith('host_'): hostIfaces.append(iface[5:]) else: riosIfaces.append(iface) name = self.fields.get('addDump_captureName', '').strip() bufferSize = self.fields.get('addDump_bufferSize') snapLength = self.fields.get('addDump_snapLength') rotateCount = self.fields.get('addDump_rotation', '0') fileSize = self.fields.get('addDump_captureMax', '0') duration = self.fields.get('addDump_captureDuration', '0') flags = self.fields.get('addDump_flags', '') vlan = self.fields.get('addDump_vlanEnable') # for the ip and port fields, parse the comma-delimited list # return an empty list for the default cases def listOrEmpty(name): val = self.fields.get(name, '').strip().lower() if val in ('', 'all', '0.0.0.0', '0'): return [] return map(str.strip, val.split(',')) sched = self.fields.get('addDump_schedule') args = [('rotate_count', 'uint32', rotateCount), ('custom', 'string', flags)] + \ [('sip', 'ipv4addr', si) for si in listOrEmpty('addDump_srcIps')] + \ [('sport', 'uint16', sp) for sp in listOrEmpty('addDump_srcPorts')] + \ [('dip', 'ipv4addr', di) for di in listOrEmpty('addDump_dstIps')] + \ [('dport', 'uint16', dp) for dp in listOrEmpty('addDump_dstPorts')] if '0' != duration: args.append(('duration', 'duration_sec', duration)) if '0' != fileSize: args.append(('file_size', 'uint32', fileSize)) if bufferSize: args.append(('buffer_size', 'uint32', bufferSize)) if snapLength: args.append(('snap_len', 'uint32', snapLength)) if name: args.append(('cap_name', 'string', name)) if 'true' == vlan: args.append(('dot1q', 'bool', 'true')) if 'true' == sched: schedDate = self.fields.get('addDump_scheduleDate', '') schedTime = self.fields.get('addDump_scheduleTime', '') args.append(('sched_date', 'date', schedDate)) args.append(('sched_time', 'time_sec', schedTime)) if riosIfaces: riosArgs = list(args) riosArgs += [('interface', 'string', iface) for iface in riosIfaces] self.sendAction('/rbt/tcpdump/action/start', *riosArgs) if hostIfaces: hostArgs = list(args) hostArgs += [('interface', 'string', iface) for iface in hostIfaces] self.sendAction('/host/tcpdump/action/start', *hostArgs) if not riosIfaces and not hostIfaces: self.setFormError('An interface must be selected.') elif 'removeTcpCaptures': captures = FormUtils.getPrefixedFieldNames('select_', self.fields) riosCaptures = Nodes.getMgmtLocalChildrenNames(self.mgmt, '/rbt/tcpdump/state/capture') if RVBDUtils.isBOB(): hostCaptures = Nodes.getMgmtLocalChildrenNames(self.mgmt, '/host/tcpdump/state/capture') for capture in captures: name, runningOn = capture.split('/') # it could have finished while the user was admiring the page if runningOn == 'RiOS' and name in riosCaptures: self.sendAction('/rbt/tcpdump/action/stop', ('cap_name', 'string', name)) elif runningOn == 'Hypervisor' and name in hostCaptures: self.sendAction('/host/tcpdump/action/stop', ('cap_name', 'string', name))