Ejemplo n.º 1
0
    def monitoredPorts(self):
        base = RVBDUtils.monitoredPortsPath(self.fields)

        if 'addPort' in self.fields.keys():
            number = self.fields.get('addPort_number')
            if Nodes.present(self.mgmt, '%s/%s' % (base, number)):
                self.setFormError("Port %s is already being monitored." % number)
                return
            else:
                desc = self.fields.get('addPort_desc')
                self.setNodes(('%s/%s/desc' % (base, number), 'string', desc))
        elif 'removePorts' in self.fields.keys():
            FormUtils.deleteNodesFromConfigForm(self.mgmt, base, 'ck_', self.fields)
        elif 'editPort' in self.fields.keys():
            number = self.fields.get('editPort_number', None)
            desc = self.fields.get('editPort_desc', None)
            self.setNodes(('%s/%s/desc' % (base, number), 'string', desc))
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
0
    def jobsXmldata(self):
        jobs = Nodes.getMgmtSetEntriesDeep(self.mgmt, '/sched/job')
        jobIds = jobs.keys()
        jobIds.sort(FormUtils.compareStringInts)
        gmStartEpoch = time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(0))
        localStartEpoch = time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(0))
        result = self.doc.createElement('jobs')
        for jobId in jobIds:
            job = jobs[jobId]
            # We need to skip over jobs where we only have the ID but no other
            # parameters (otherwise, an RBM user can only schedule new jobs if
            # they were the one who scheduled the earlier one, assuming no
            # holes - see bug 105123 for details). The enable state is reliably
            # available for jobs (the name may not always exist), so use that
            # as the test for whether the job exists but is denied.
            if not job.get('enable', None):
                continue

            outputInfo = 'None.'
            outputFile = Nodes.present(self.mgmt, '/sched/job/%s/output_file' % jobId, '')
            if outputFile:
                try:
                    outputLines = file(outputFile).readlines()
                    if outputLines and len(outputLines) > 0:
                        outputInfo = '#012;'
                        for outputLine in outputLines:
                            outputInfo += '%s#012;' % cgi.escape(outputLine)
                except:
                    outputInfo = 'None.'

            jobEl = self.doc.createElement('job')
            jobEl.setAttribute('jobId', jobId)
            jobEl.setAttribute('name', job['name'])
            jobEl.setAttribute('comment', job['comment'])
            jobEl.setAttribute('output', outputInfo)
            status = job.get('status', "unknown")
            errorString = job.get('error_string', "")
            # if errorString and 'completed' == status:
            if errorString:
                status = 'error'
            jobEl.setAttribute('status', status)
            jobEl.setAttribute('statusIcon', 'icon_job_%s.gif' % status)
            if not errorString:
                errorString = status.capitalize()
            jobEl.setAttribute('statusDetail', errorString)
            frequency = job.get('recurring', '0')
            jobEl.setAttribute('frequencySeconds', frequency)
            jobEl.setAttribute('frequencyLang', iph(int(frequency)).then(
                'Recurs every %s seconds' % frequency, 'Not recurring'))
            jobEl.setAttribute('recurs', iph(int(frequency)).then('Y', 'N'))
            jobEl.setAttribute('recurIcon', iph(int(frequency)).then(
                'icon_refresh.gif', 'icon_job_once.gif'))
            jobEl.setAttribute('enabled',
                ('true' == job['enable']) and 'enabled' or 'disabled')
            datetime = ' '.join((job['date'], job['time']))
            if gmStartEpoch == datetime:
                datetime = ""
            jobEl.setAttribute('datetime', datetime)
            datetime = job.get('create_time', '')
            if localStartEpoch == datetime:
                datetime = ""
            jobEl.setAttribute('creation', datetime)
            datetime = job.get('last_exec_time', '')
            if localStartEpoch == datetime:
                datetime = ""
            jobEl.setAttribute('lastrun', datetime)
            commandSeqs = [x.split('/')[-1]
                for x in job.keys()
                if x.startswith('commands/') and not x.endswith('/command')]
            commandSeqs.sort(FormUtils.compareStringInts)
            for eachSeq in commandSeqs:
                command = job['commands/%s/command' % eachSeq]
                commandEl = self.doc.createElement('command')
                commandEl.setAttribute('instruction', command)
                jobEl.appendChild(commandEl)
            result.appendChild(jobEl)
        self.doc.documentElement.appendChild(result)
        self.writeXmlDoc()
Ejemplo n.º 4
0
    def jobsXmldata(self):
        jobs = Nodes.getMgmtSetEntriesDeep(self.mgmt, '/sched/job')
        jobIds = jobs.keys()
        jobIds.sort(FormUtils.compareStringInts)
        gmStartEpoch = time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(0))
        localStartEpoch = time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(0))
        result = self.doc.createElement('jobs')
        for jobId in jobIds:
            outputInfo = 'None.'
            outputFile = Nodes.present(self.mgmt, '/sched/job/%s/output_file' % jobId, '')
            if outputFile:
                try:
                    outputLines = file(outputFile).readlines()
                    if outputLines and len(outputLines) > 0:
                        outputInfo = '#012;'
                        for outputLine in outputLines:
                            outputInfo += '%s#012;' % cgi.escape(outputLine)
                except:
                    outputInfo = 'None.'

            job = jobs[jobId]
            jobEl = self.doc.createElement('job')
            jobEl.setAttribute('jobId', jobId)
            jobEl.setAttribute('name', job['name'])
            jobEl.setAttribute('comment', job['comment'])
            jobEl.setAttribute('output', outputInfo)
            status = job.get('status', "unknown")
            errorString = job.get('error_string', "")
            # if errorString and 'completed' == status:
            if errorString:
                status = 'error'
            jobEl.setAttribute('status', status)
            jobEl.setAttribute('statusIcon', 'icon_job_%s.gif' % status)
            if not errorString:
                errorString = status.capitalize()
            jobEl.setAttribute('statusDetail', errorString)
            frequency = job.get('recurring', '0')
            jobEl.setAttribute('frequencySeconds', frequency)
            jobEl.setAttribute('frequencyLang', iph(int(frequency)).then(
                'Recurs every %s seconds' % frequency, 'Not recurring'))
            jobEl.setAttribute('recurs', iph(int(frequency)).then('Y', 'N'))
            jobEl.setAttribute('recurIcon', iph(int(frequency)).then(
                'icon_refresh.gif', 'icon_job_once.gif'))
            jobEl.setAttribute('enabled',
                ('true' == job['enable']) and 'enabled' or 'disabled')
            datetime = ' '.join((job['date'], job['time']))
            if gmStartEpoch == datetime:
                datetime = ""
            jobEl.setAttribute('datetime', datetime)
            datetime = job.get('create_time', '')
            if localStartEpoch == datetime:
                datetime = ""
            jobEl.setAttribute('creation', datetime)
            datetime = job.get('last_exec_time', '')
            if localStartEpoch == datetime:
                datetime = ""
            jobEl.setAttribute('lastrun', datetime)
            commandSeqs = [x.split('/')[-1]
                for x in job.keys()
                if x.startswith('commands/') and not x.endswith('/command')]
            commandSeqs.sort(FormUtils.compareStringInts)
            for eachSeq in commandSeqs:
                command = job['commands/%s/command' % eachSeq]
                commandEl = self.doc.createElement('command')
                commandEl.setAttribute('instruction', command)
                jobEl.appendChild(commandEl)
            result.appendChild(jobEl)
        self.doc.documentElement.appendChild(result)
        self.writeXmlDoc()