Ejemplo n.º 1
0
    def check_attributes(self, attrs='', load=False, t0=0):

        db, t0, result, vals = self, t0 or fn.now(), {}, {}
        print('Checking %s' % str(db))

        if fn.isDictionary(attrs):
            attrs, vals = attrs.keys(), attrs
            if isinstance(vals.values()[0], dict):
                vals = dict((k, v.values()[0]) for k, v in vals.items())
        else:
            if fn.isString(attrs):
                attrs = fn.filtersmart(db.get_attributes(), attrs)
                load = True

        if load:
            [vals.update(db.load_last_values(a)) for a in attrs]

        print('\t%d attributes' % len(attrs))
        result['attrs'] = attrs
        result['vals'] = vals
        result['novals'] = [a for a, v in vals.items() if not v]
        result['nones'], result['down'], result['lost'] = [], [], []
        for a, v in vals.items():
            if not v or [1] is None:
                if not fn.read_attribute(a):  #USE read not check!!
                    result['down'].append(a)
                else:
                    result['novals' if not v else 'nones'].append(a)
            elif v[0] < (t0 - 7200):
                result['lost'].append(a)

        print('\t%d attributes have no values' % len(result['novals']))
        print('\t%d attributes are not readable' % len(result['down']))
        print('\t%d attributes are not updated' % len(result['lost']))
        print('\t%d attributes have None values' % len(result['nones']))

        return result
Ejemplo n.º 2
0
    def check_attributes(self,attrs = '', load = False, t0 = 0):
        
        db,t0,result,vals = self,t0 or fn.now(),{},{}
        print('Checking %s' % str(db))

        if fn.isDictionary(attrs):
            attrs,vals = attrs.keys(),attrs
            if isinstance(vals.values()[0],dict):
                vals = dict((k,v.values()[0]) for k,v in vals.items())
        else:
            if fn.isString(attrs):
                attrs = fn.filtersmart(db.get_attributes(),attrs)
                load = True

        if load:
            [vals.update(db.load_last_values(a)) for a in attrs]

        print('\t%d attributes'%len(attrs))
        result['attrs'] = attrs
        result['vals'] = vals
        result['novals'] = [a for a,v in vals.items() if not v]
        result['nones'],result['down'],result['lost'] = [],[],[]
        for a,v in vals.items():
            if not v or [1] is None:
                if not fn.read_attribute(a): #USE read not check!!
                    result['down'].append(a)
                else:
                    result['novals' if not v else 'nones'].append(a)
            elif v[0] < (t0 - 7200):
                result['lost'].append(a)
        
        print('\t%d attributes have no values'%len(result['novals']))
        print('\t%d attributes are not readable'%len(result['down']))
        print('\t%d attributes are not updated'%len(result['lost']))
        print('\t%d attributes have None values'%len(result['nones']))
        
        return result    
Ejemplo n.º 3
0
    def __init__(self,
                 parent=None,
                 filters='',
                 options=None,
                 mainwindow=None,
                 api=None):

        options = options or {}
        if not fn.isDictionary(options):
            options = dict(
                (o.replace('-', '').split('=')[0], o.split('=', 1)[-1])
                for o in options)

        trace('In AlarmGUI(%s): %s' % (filters, options))

        self.last_reload = 0
        self.AlarmRows = {}
        self.timeSortingEnabled = None
        self.changed = True
        self.severities = []  #List to keep severities currently visible

        self.expert = False
        self.tools = {}  #Widgets dictionary

        self.scope = options.get('scope', '*')  #filters or '*'
        self.default_regEx = options.get('default', filters or '*')
        self.regEx = self.default_regEx
        self.init_ui(parent, mainwindow)  #init_mw is called here
        self.NO_ICON = Qt.QIcon()

        refresh = int(options.get('refresh', self.REFRESH_TIME))
        self.REFRESH_TIME = refresh
        #AlarmRow.REFRESH_TIME = refresh

        #if self.regEx not in ('','*'):
        #print 'Setting RegExp filter: %s'%self.regEx
        #self._ui.regExLine.setText(str(self.regEx))

        self.api = api or panic.AlarmAPI(self.scope)
        trace('AlarmGUI(%s): api done' % self.scope)

        # @TODO: api-based views are not multi-host
        self.view = panic.view.AlarmView(api=self.api,
                                         scope=self.scope,
                                         refresh=self.REFRESH_TIME / 1e3,
                                         events=False,
                                         verbose=1)
        trace('AlarmGUI(): view done')

        self.snapi = None
        self.ctx_names = []

        if not self.api.keys(): trace('NO ALARMS FOUND IN DATABASE!?!?')
        #AlarmRow.TAG_SIZE = 1+max([len(k) for k in self.api] or [40])

        N = len(self.getAlarms())
        trace('AlarmGUI(): %d alarms' % N)
        if 1:  #N<150:
            #self._ui.sevDebugCheckBox.setChecked(True)
            self._ui.activeCheckBox.setChecked(False)
        #else:
        #self._ui.sevDebugCheckBox.setChecked(False)
        #self._ui.activeCheckBox.setChecked(True)

        if N <= self.MAX_ALARMS: self.USE_EVENT_REFRESH = True

        self.init_timers()
        self.init_filters()

        trace('AlarmGUI(): signals done')
        ## connection of ui signals is delayed until first onRefresh()

        self.updateStatusLabel()

        trace('AlarmGUI(): done')
Ejemplo n.º 4
0
    def __init__(self, parent=None, filters='*', options=None, mainwindow=None):
        print '>'*80
        options = options or {}
        if not fandango.isDictionary(options):
            options = dict((o.replace('--','').split('=')[0],o.split('=',1)[-1]) for o in options)
        trace( 'In AlarmGUI(%s): %s'%(filters,options))
        PARENT_CLASS.__init__(self,parent)
        self._ui = Ui_AlarmList()
        self._ui.setupUi(self)
        self.last_reload = 0
        self.filters = filters
        self.mainwindow = mainwindow

        self._ordered=[] #Alarms list ordered
        self.AlarmRows = {}
        self.timeSortingEnabled=None
        self.changed = True
        self.expert = False
        self.tools = {} #Widgets dictionary
        try:
            px = QtGui.QPixmap('/homelocal/sicilia/applications/Panic/PanicBanner.gif')
            self.splash = QtGui.QSplashScreen(px)
            self.splash.showMessage('initializing application...')
            self.splash.show()
            print 'showing splash ... %s'%px.size()
        except: print traceback.format_exc()

        self._message = QtGui.QMessageBox(self)
        self._message.setWindowTitle("Empty fields")
        self._message.setIcon(QtGui.QMessageBox.Critical)

        self.api = panic.AlarmAPI()
        self.default_regEx=options.get('filter',None) or filters or None
        self.regEx = self.default_regEx
        if self.regEx and str(self.regEx)!=os.getenv('PANIC_DEFAULT'): 
            print 'Setting RegExp filter: %s'%self.regEx
            self._ui.regExLine.setText(str(self.regEx))
        self.severities=['alarm', 'error', 'warning', 'debug', '']
        self.setExpertView(False)
        self.setExpertView(True) #checked=('expert' in options))
        
        if self.mainwindow:
            #self.mainwindow.setWindowTitle(str(os.getenv('TANGO_HOST')).split(':',1)[0]+' Alarm Widget (%s)'%self.filters)
            self.mainwindow.setWindowTitle('PANIC (%s@%s)'%(self.filters or self.regEx or '',str(os.getenv('TANGO_HOST')).split(':',1)[0]))
            
        try:
            assert SNAP_ALLOWED
            self.snapi=snap.SnapAPI()
            self.ctx_names=[c.name for c in self.snapi.get_contexts().values()]
        except:
            self.snapi = None
            self.ctx_names = []

        if not self.api.keys(): trace('NO ALARMS FOUND IN DATABASE!?!?')
        AlarmRow.TAG_SIZE = 1+max([len(k) for k in self.api] or [40])
        N = len(self.getAlarms())
        if N<150: 
            self._ui.sevDebugCheckBox.setChecked(True)
            self._ui.activeCheckBox.setChecked(False)
            self.REFRESH_TIME = 5000
            AlarmRow.REFRESH_TIME = 5000
        else:
            self._ui.sevDebugCheckBox.setChecked(False)
            self._ui.activeCheckBox.setChecked(True)
            self.severities.remove('debug')
        if N<=self.MAX_ALARMS: self.USE_EVENT_REFRESH = True

        #self.connectAll()
        #self.buildList()
        self._connected = False
        self.modelsQueue = Queue.Queue()
        self.modelsThread = fandango.qt.TauEmitterThread(parent=self,queue=self.modelsQueue,method=self.setAlarmRowModel)
        self.modelsThread.start()
        #TIMERS (to reload database and refresh alarm list).
        self.reloadTimer = QtCore.QTimer()
        self.refreshTimer = QtCore.QTimer()
        QtCore.QObject.connect(self.refreshTimer, QtCore.SIGNAL("timeout()"), self.onRefresh)
        QtCore.QObject.connect(self.reloadTimer, QtCore.SIGNAL("timeout()"), self.onReload)
        self.reloadTimer.start(5000.)
        self.refreshTimer.start(2*self.REFRESH_TIME)
        
        self.source = "" #Value in first comboBox
        self.setFirstCombo()
        self.setSecondCombo()
        self._ui.infoLabel0_1.setText(self._ui.contextComboBox.currentText())
        self.updateStatusLabel()