Logo Search packages:      
Sourcecode: nagstamon version File versions  Download package

def Nagstamon::nagstamonGUI::GUI::RefreshDisplayStatus (   self  ) 

    load current nagios status and refresh trayicon and detailed treeview
    add only services which are not on maintained or acknowledged hosts
    this way applying the nagios filter more comfortably because in
    nagios one had to schedule/acknowledge every single service

Definition at line 177 of file nagstamonGUI.py.

00177                                   :
        """
            load current nagios status and refresh trayicon and detailed treeview
            add only services which are not on maintained or acknowledged hosts
            this way applying the nagios filter more comfortably because in
            nagios one had to schedule/acknowledge every single service
        """
        # refresh statusbar

        # flag for overall status, needed by popwin.popup to decide if popup in case all is OK
        self.status_ok = False    
        
        # local counters for summarize all miserable hosts
        downs = 0
        unreachables = 0
        unknowns = 0
        criticals = 0
        warnings = 0    
        
        # walk through all servers, their hosts and their services
        for server in self.servers.values():
            # only refresh Nagios server output if enabled
            if str(self.conf.servers[server.name].enabled) == "True":
                try:
                    # otherwise it must be shown, full of problems
                    self.popwin.ServerVBoxes[server.name].show()
                    self.popwin.ServerVBoxes[server.name].set_no_show_all(False)
                    # use a bunch of filtered nagitems, services and hosts sorted by different
                    # grades of severity
                    
                    # summarize states
                    downs += server.downs
                    unreachables += server.unreachables
                    unknowns += server.unknowns
                    criticals += server.criticals
                    warnings += server.warnings    
                    
                    # if there is no trouble...
                    if len(server.nagitems_filtered["hosts"]["DOWN"]) == 0 and \
                        len(server.nagitems_filtered["hosts"]["UNREACHABLE"]) == 0 and \
                        len(server.nagitems_filtered["services"]["CRITICAL"]) == 0 and \
                        len(server.nagitems_filtered["services"]["WARNING"]) == 0 and \
                        len(server.nagitems_filtered["services"]["UNKNOWN"]) == 0:
                        # ... there is no need to show a label or treeview...
                        self.popwin.ServerVBoxes[server.name].hide()
                        self.popwin.ServerVBoxes[server.name].set_no_show_all(True)
                    else:
                        # otherwise it must be shown, full of problems
                        self.popwin.ServerVBoxes[server.name].show()
                        self.popwin.ServerVBoxes[server.name].set_no_show_all(False)                
                    
                    # fill treeview for popwin
                    # create a model for treeview where the table headers all are strings
                    tab_model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
                    
                    # apart from status informations there we need two columns which
                    # hold the color information, which is derived from status which
                    # is used as key at the above color dictionaries
                    
                    # show hosts first to recognize down ones first, hosts and services
                    # ordered by severity
                    for status in ["DOWN", "UNREACHABLE"]:
                        # sort hosts by name
                        server.nagitems_filtered["hosts"][status].sort(key=lambda obj: obj.name)
                        # put in sorted hosts
                        for host in server.nagitems_filtered["hosts"][status]:
                            iter = tab_model.insert_before(None, None)
                            tab_model.set_value(iter, 0, str(host.name))
                            tab_model.set_value(iter, 2, str(host.status))
                            tab_model.set_value(iter, 3, str(host.last_check))                
                            tab_model.set_value(iter, 4, str(host.duration))
                            tab_model.set_value(iter, 5, str(host.attempt))             
                            tab_model.set_value(iter, 6, str(host.status_information))
                            tab_model.set_value(iter, 7, self.tab_bg_colors[host.status])
                            tab_model.set_value(iter, 8, self.tab_fg_colors[host.status])
                    
                    for status in ["CRITICAL", "UNKNOWN", "WARNING"]:
                        # sort services by host and service name
                        server.nagitems_filtered["services"][status].sort(key=lambda obj: obj.host + obj.name)
                        # put in sorted services
                        for service in server.nagitems_filtered["services"][status]:
                            iter = tab_model.insert_before(None, None)
                            tab_model.set_value(iter, 0, str(service.host))
                            tab_model.set_value(iter, 1, str(service.name))
                            tab_model.set_value(iter, 2, str(service.status))
                            tab_model.set_value(iter, 3, str(service.last_check))  
                            tab_model.set_value(iter, 4, str(service.duration))
                            tab_model.set_value(iter, 5, str(service.attempt))  
                            tab_model.set_value(iter, 6, str(service.status_information))
                            tab_model.set_value(iter, 7, self.tab_bg_colors[service.status])
                            tab_model.set_value(iter, 8, self.tab_fg_colors[service.status])
                    
                    # http://www.pygtk.org/pygtk2reference/class-gtktreeview.html#method-gtktreeview--set-model         
                    # clear treeviews columns
                    for c in self.popwin.ServerVBoxes[server.name].TreeView.get_columns():
                        self.popwin.ServerVBoxes[server.name].TreeView.remove_column(c)

                    # give new model to the view, overwrites the old one automatically
                    self.popwin.ServerVBoxes[server.name].TreeView.set_model(tab_model)
                    
                    # render aka create table view
                    tab_renderer = gtk.CellRendererText()
                    tab_column_names = ["Host", "Service", "Status", "Last Check", "Duration", "Attempt", "Status Information"]
                    for s in range(len(tab_column_names)):
                        # fill columns of view with content of model and squeeze it through the renderer, using
                        # the color information from the last to colums of the model
                        tab_column = gtk.TreeViewColumn(tab_column_names[s], tab_renderer, text=s, background=7, foreground=8)
                        self.popwin.ServerVBoxes[server.name].TreeView.append_column(tab_column)
                        
                    # status field in server vbox in popwin    
                    self.popwin.UpdateStatus(server)
                    
                except:
                    pass

        # show and resize popwin
        self.popwin.VBox.hide_all()
        self.popwin.VBox.show_all()
        self.popwin.Resize()
        
        # everything OK
        if unknowns == 0 and warnings == 0 and criticals == 0 and unreachables == 0 and downs == 0:
            self.statusbar.statusbar_labeltext = '<span size="%s" background="darkgreen" foreground="white"> OK </span>' % (self.fontsize)
            self.statusbar.statusbar_labeltext_inverted = self.statusbar.statusbar_labeltext
            self.statusbar.Label.set_markup(self.statusbar.statusbar_labeltext)
            # fix size when loading with network errors
            self.statusbar.Resize()
            # if all is OK there is no need to pop up popwin so set self.showPopwin to False
            self.popwin.showPopwin = False
            self.popwin.Close()
            self.status_ok = True
            # set systray icon to green aka OK
            self.statusbar.SysTray.set_from_file(self.Resources + "/nagstamon_green" + self.BitmapSuffix)
            # switch notification off
            self.NotificationOff()
        else:
            self.status_ok = False
            
            # put text for label together

            self.statusbar.statusbar_labeltext = self.statusbar.statusbar_labeltext_inverted = ""
            
            if downs > 0:
                if str(self.conf.long_display) == "True": downs = str(downs) + " DOWN"
                self.statusbar.statusbar_labeltext = '<span size="%s" background="black" foreground="white"> ' % (self.fontsize) + str(downs) + ' </span>'
                self.statusbar.statusbar_labeltext_inverted = '<span size="%s" background="white" foreground="black"> ' % (self.fontsize) + str(downs) + ' </span>'
            if unreachables > 0:
                if str(self.conf.long_display) == "True": unreachables = str(unreachables) + " UNREACHABLE"
                self.statusbar.statusbar_labeltext = self.statusbar.statusbar_labeltext + '<span size="%s" background="darkred" foreground="white"> ' % (self.fontsize) + str(unreachables) + ' </span>'
                self.statusbar.statusbar_labeltext_inverted = self.statusbar.statusbar_labeltext_inverted + '<span size="%s" background="white" foreground="darkred"> ' % (self.fontsize) + str(unreachables) + ' </span>'
            if criticals > 0:
                if str(self.conf.long_display) == "True": criticals = str(criticals) + " CRITICAL"
                self.statusbar.statusbar_labeltext = self.statusbar.statusbar_labeltext + '<span size="%s" background="red" foreground="white"> ' % (self.fontsize) + str(criticals) + ' </span>'
                self.statusbar.statusbar_labeltext_inverted = self.statusbar.statusbar_labeltext_inverted + '<span size="%s" background="white" foreground="red"> ' % (self.fontsize) + str(criticals) + ' </span>'
            if unknowns > 0:
                if str(self.conf.long_display) == "True": unknowns = str(unknowns) + " UNKNOWN"
                self.statusbar.statusbar_labeltext = self.statusbar.statusbar_labeltext + '<span size="%s" background="orange" foreground="black"> ' % (self.fontsize) + str(unknowns) + ' </span>'
                self.statusbar.statusbar_labeltext_inverted = self.statusbar.statusbar_labeltext_inverted + '<span size="%s" background="black" foreground="orange"> ' % (self.fontsize) + str(unknowns) + ' </span>'
            if warnings > 0:
                if str(self.conf.long_display) == "True": warnings = str(warnings) + " WARNING"
                self.statusbar.statusbar_labeltext = self.statusbar.statusbar_labeltext + '<span size="%s" background="yellow" foreground="black"> ' % (self.fontsize) + str(warnings) + ' </span>'
                self.statusbar.statusbar_labeltext_inverted = self.statusbar.statusbar_labeltext_inverted + '<span size="%s" background="black" foreground="yellow"> ' % (self.fontsize) + str(warnings) + ' </span>'

            # put text into label in statusbar, only if not already flashing
            if self.statusbar.Flashing == False:
                self.statusbar.Label.set_markup(self.statusbar.statusbar_labeltext)
                
            # Windows workaround for non-automatically-shrinking desktop statusbar
            if str(self.conf.statusbar_floating) == "True":
                self.statusbar.Resize()
                
            # choose icon for systray  - the worst case decides the shown color
            if warnings > 0: color = "yellow"
            if unknowns > 0: color = "orange"
            if criticals > 0: color = "red"
            if unreachables > 0: color = "darkred"
            if downs > 0: color = "black"

            self.statusbar.SysTray.set_from_file(self.Resources + "/nagstamon_" + color + self.BitmapSuffix)
            
            # if there hase been any status change notify user
            # first find out which of all servers states is the worst similar to nagstamonObjects.GetStatus()
            worst = 0
            worst_status = "OK"
            for server in self.servers.values():
                if not server.WorstStatus == "OK":
                    # switch server status back because it has been recognized
                    if server.States.index(server.WorstStatus) > worst:
                            worst_status = server.WorstStatus
                    # reset status of the server for only processing it once
                    server.WorstStatus = "OK"

                # debug
                if str(self.conf.debug_mode) == "True":
                    print "worst_status:", worst_status
                    
                if not worst_status == "OK" and str(self.conf.notification)== "True":
                    self.NotificationOn(status=worst_status)
            
            # set self.showPopwin to True because there is something to show
            self.popwin.showPopwin = True        
              
        # do some cleanup
        gc.collect()
        
        # return False to get removed as gobject idle source
        return False


    def AcknowledgeDialogShow(self, server, host, service=None):


Generated by  Doxygen 1.6.0   Back to index