Esempio n. 1
0
    def get_data(self, params):
        """Loads HTML from Nagios installation with information requested in params.
        """    
        username = str()
        password = str()
        try:
            username = base64.b64decode(gconf.client_get_default().get_string('/apps/maegios/username'))
            password = base64.b64decode(gconf.client_get_default().get_string('/apps/maegios/password'))
        except:
            pass

        # todo: add support for digest authentication
        base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
        headers = {'Authorization': 'Basic %s' % base64string}
        url = gconf.client_get_default().get_string('/apps/maegios/url').split('/')
        socket.setdefaulttimeout(5)
        if url[0][4] == 's':
            connection = httplib.HTTPSConnection(url[2])
        else:
            connection = httplib.HTTPConnection(url[2])
        connection.request('POST', '/%s/%s' % (url[3], 'cgi-bin/status.cgi'), params, headers)
        response = connection.getresponse()
        data = str()
        if response.status != 200:
            raise Exception     
        else:
            data = response.read()
            if len(data) == 0:
                raise Exception

        connection.close()
        return data
Esempio n. 2
0
    def display(self, widget):
        # Create the main window
        self.window = hildon.StackableWindow()
        self.window.set_title(_(u"Refresh Settings"))

        label1 = gtk.Label(_(u"Refresh Interval:"))
        label1.set_width_chars(15)
        label1.set_alignment(1.0, 0.5)
        label2 = gtk.Label(_(u"Attempts:"))
        label2.set_width_chars(15)
        label2.set_alignment(1.0, 0.5)
        label3 = gtk.Label(_(u"minutes"))
        label3.set_alignment(0.1, 0.5)

        self.entryInterval = hildon.Entry(3)
        self.entryInterval.set_max_length(5)
        self.entryInterval.set_text(gconf.client_get_default().get_string('/apps/maegios/interval'))
        self.entryAttempts = hildon.Entry(3)
        self.entryAttempts.set_max_length(5)
        self.entryAttempts.set_text(gconf.client_get_default().get_string('/apps/maegios/attempts'))

        self.buttonSave = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | 
                                        gtk.HILDON_SIZE_FINGER_HEIGHT,
                                        hildon.BUTTON_ARRANGEMENT_VERTICAL)
        self.buttonSave.set_label(_(u"Save"))

        self.buttonUndo = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | 
                                        gtk.HILDON_SIZE_FINGER_HEIGHT,
                                        hildon.BUTTON_ARRANGEMENT_VERTICAL)
        self.buttonUndo.set_label(_(u"Clear"))

        vbox = gtk.VBox(True, 1)

        # Interval
        hboxInterval = gtk.HBox(False, 0)
        hboxInterval.pack_start(label1, False, False, 20)
        hboxInterval.pack_start(self.entryInterval, False, False, 20)
        hboxInterval.pack_start(label3, False, False, 0)
        vbox.pack_start(hboxInterval, False, False, 0)

        # Attempts
        hboxAttempts = gtk.HBox(False, 0)
        hboxAttempts.pack_start(label2, False, False, 20)
        hboxAttempts.pack_start(self.entryAttempts, False, False, 20)
        vbox.pack_start(hboxAttempts, False, False, 0)

        buttonBox = gtk.HBox(False, 0)
        buttonBox.pack_start(self.buttonSave, True, True, 50)
        buttonBox.pack_start(self.buttonUndo, True, True, 50)

        vbox.pack_start(buttonBox, True, False, 0)

        self.window.add(vbox)

        self.buttonSave.connect("clicked", self.save)
        self.buttonUndo.connect("clicked", self.undo)

        # This call show the window and also add the window to the stack
        self.window.show_all()
Esempio n. 3
0
    def save(self, button):
        """Saves Nagios server settings to gconf
        """
        gconf.client_get_default().set_string('/apps/maegios/url',\
        self.entryUrl.get_text())
        gconf.client_get_default().set_string('/apps/maegios/username',\
        base64.b64encode(self.entryUsername.get_text()))
        gconf.client_get_default().set_string('/apps/maegios/password',\
        base64.b64encode(self.entryPassword.get_text()))
        
        previous_is_configured_value = int(gconf.client_get_default().get_string('/apps/maegios/is_configured'))

        gconf.client_get_default().set_string('/apps/maegios/is_configured', '1')

        # notify desktop widget that configuration has been changed
        self.toplevel.reload_widget()

        # refresh treeview
        self.toplevel.refresh()
        
        # display pannable area if we haven't yet
        if previous_is_configured_value == 0:
            if len(self.toplevel.window.get_children()) > 0:
                self.toplevel.window.remove(self.toplevel.window.get_children()[0])  
            self.toplevel.window.add(self.toplevel.parea)
            self.toplevel.window.show_all()

        button.get_toplevel().get_stack().pop(1)

        # configuration note, todo: localization
        note = hildon.hildon_note_new_information(button.get_toplevel(), \
           _(u"Your Nagios configuration has been saved, and will now be used \
to pull information from your Nagios instance."))
        response = gtk.Dialog.run(note)
Esempio n. 4
0
    def __init__(self, toplevel = None):
        threading.Thread.__init__(self)
        
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.bind(('', 0))
        self.socket.listen(1)

        gconf.client_get_default().set_int('/apps/maegios/widget_port', self.socket.getsockname()[1])
        
        self.quitting = False
        self.toplevel = toplevel
        self.setDaemon(True)
        self.start()
Esempio n. 5
0
    def display(self):
        self.window = hildon.StackableWindow()
        
        # Set window title
        self.window.set_title("Maegios")
        # Create menu
        self.label2 = gtk.Label(_(u"No menu option has been selected yet."))
        self.menu = self.create_menu(self.label2)
        # Attach menu to the window
        self.window.set_app_menu(self.menu)

        self.parea = hildon.PannableArea()
        self.parea.set_property("mov-mode", hildon.MOVEMENT_MODE_BOTH);
        # gtk.HILDON_UI_MODE_NORMAL -> not selection in the treeview
        # gtk.HILDON_UI_MODE_EDIT -> selection in the treeview
        self.treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_EDIT)
        # this is pointless if we haven't been configured
        if int(gconf.client_get_default().get_string('/apps/maegios/is_configured')) == 1:
            # load data from nagios asynchronously
            self.model = self.create_model_loading()
            self.treeview.set_model(self.model)
            self.thread = threading.Thread(target = self.async_fetch)
            self.thread.start()
        
        #self.treeview.set_level_indentation(30)
        self.add_columns_to_treeview(self.treeview)
        self.treeview.columns_autosize()
        self.parea.add(self.treeview)
        #self.parea.scroll_to(0, 0)
        self.treeview.expand_all()

        if int(gconf.client_get_default().get_string('/apps/maegios/is_configured')) == 0:
            label = gtk.Label(_(u"Please configure Maegios with information about your Nagios instance."))
            button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | 
                                   gtk.HILDON_SIZE_FINGER_HEIGHT,
                                   hildon.BUTTON_ARRANGEMENT_VERTICAL)
            button.set_label(_(u"Nagios Configuration"))
            dialog = UINagiosConfigurationDialog(self)             
            button.connect("clicked", dialog.display)
            self.vbox = gtk.VBox(True, 80)
            self.vbox.set_spacing(15)
            self.vbox.pack_start(label, False, False, 0)
            self.vbox.pack_start(button, False, False, 0)
            self.window.add(self.vbox)
        else:
            self.window.add(self.parea)
        
        self.window.connect("destroy", self.quit)
        
        self.window.show_all()
Esempio n. 6
0
    def save(self, button):
        """Saves refresh settings to gconf
        """
        gconf.client_get_default().set_string('/apps/maegios/interval', self.entryInterval.get_text())
        gconf.client_get_default().set_string('/apps/maegios/attempts', self.entryAttempts.get_text())

        # notify desktop widget that configuration has been changed
        self.toplevel.reload_widget()

        # refresh treeview
        self.toplevel.refresh()

        button.get_toplevel().get_stack().pop(1)

        # configuration note
        note = hildon.hildon_note_new_information(button.get_toplevel(), \
           _(u"Your refresh settings have been saved, and will now be used \
to pull information from your Nagios instance."))
        response = gtk.Dialog.run(note)
Esempio n. 7
0
 def reload_widget(self):
     """Signals desktop widget to reload on configuration change
     """
     try:
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.connect(('', gconf.client_get_default().get_int('/apps/maegios/widget_port')))
         s.send('RE')
         data = s.recv(2)
         s.close()
     except:
         pass
Esempio n. 8
0
    def __init__(self, component_manager):
        Component.__init__(self, component_manager)
        self.widgets = {}

        # enable functionality if gconf entry exists
        self.gconf = gconf.client_get_default()
        try:
            self.current = self.gconf.get_value(self.gconf_entry)
            self.enabled = True
        except (gobject.GError, ValueError):
            self.enabled = False
Esempio n. 9
0
    def setup(self,cfrom):

        self.invokedfrom = cfrom
        self.button = gtk.Button()
        self.button.set_image(gtk.image_new_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU))
        self.button.set_name("menu")
        if self.invokedfrom == 1:
            self.button.set_size_request(40,40)
        elif self.invokedfrom == 2:
            self.button.set_size_request(64,64)
	    gtk.Widget.set_name( self.button, "hildon-navigator-button-one" )
        else:
            self.button.set_size_request(320,320)
        self.__create_menu()
        if self.invokedfrom != 3: ###
            self.button.connect("clicked",self.__popup_menu)
        self.button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(24000,24000,24000))
        self.button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(32000,32000,32000))
        self.button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.Color(40000,40000,40000))
        self.button.show()
        gobject.timeout_add(500,self.__updateicon)

        self.cgclnt = gconf.client_get_default()
        val = self.__getgconf( "ICONUPDATE" )
        if not val:
            val = 3
        self.iconupdate = int(val)

        if not os.path.exists("/tmp/mgpstate"):
            self.gpstfile = open("/tmp/mgpstate", "w+")
            t = "";
            for i in range(244):
                t+="\0"
            self.gpstfile.write(t)
            self.gpstfile.close()
            
        self.gpstfile = open("/tmp/mgpstate", "r+")
        self.gpstdata = mmap.mmap(self.gpstfile.fileno(), 244)

        self.cgclnt.add_dir( self.__gcpath , gconf.CLIENT_PRELOAD_NONE)

        if not cfrom:
            pass

        self.m_loop = DBusGMainLoop()
        self.bus = dbus.SystemBus(mainloop = self.m_loop, private = True)
        self.handler = self.bus.add_signal_receiver(self._inactivity_handler,
                                                    signal_name="display_status_ind",
                                                    dbus_interface='com.nokia.mce.signal',
                                                    path='/com/nokia/mce/signal')

        return self.button
Esempio n. 10
0
def setAllNight(newMode=None):
    global preferences

    # setup dim mode if needed

    client = gconf.client_get_default()
    if ci.originalDim == -1:
        ci.originalDim = \
            client.get_int('/system/osso/dsm/display/display_blank_timeout'
                           )

    if newMode == None:
        if int(preferences['allNight']) == 0:
            newMode = 1
        else:
            newMode = 0

        preferences['allNight'] = newMode

        # save updated preferences since we've toggled them; otherwise save must be called manually.

        savePrefs()

    if newMode == 1:

        # Set the dimtime to 1 day... that should do the trick!
        # and we then don't have to worry about chargers or anything since inactivity flag is only raised if screen actually goes off!

        client.set_int('/system/osso/dsm/display/display_blank_timeout'
                       , 24 * 3600)

        ci.dimChanged = 1
        print 'Set Dim'
    else:

        # and we then don't have to worry about chargers or anything since inactivity flag is only raised if screen actually goes off!

        client.set_int('/system/osso/dsm/display/display_blank_timeout'
                       , ci.originalDim)

        ci.dimChanged = 1
        print 'Cleared Dim'

    return newMode
Esempio n. 11
0
 def get_nagios_data(self):
     # Load and parse nagios data
     remainingAttempts = int(gconf.client_get_default().get_string('/apps/maegios/attempts'))
     
     while remainingAttempts > 0:
         #print "connection attempts [widget]: %d" % remainingAttempts
         try:
             parser = NagiosParser(only_active = 1)
             connector = NagiosConnector(self)
             parser.feed(connector.get_down_hosts())
             parser.close()
             break
         except:
             remainingAttempts -= 1
             time.sleep(0.1)
         
     if remainingAttempts == 0:
         return False
     else:
         return parser.get_hosts()
Esempio n. 12
0
    def run(self):
        self.window.show_all()

        self.conf_client = gconf.client_get_default()
        self.conf_client.add_dir("/apps/anki/general", gconf.CLIENT_PRELOAD_NONE)
        self.DECK_PATH = self.conf_client.get_string("/apps/anki/general/deck_path")
        self.SYNC_USERNAME = self.conf_client.get_string("/apps/anki/general/sync_username")
        self.SYNC_PASSWORD = self.conf_client.get_string("/apps/anki/general/sync_password")

        for i in range(5):
            h = self.conf_client.get_string("/apps/anki/general/deck_path_history%d"%i)
            if h:
                self.recent_decks.append(h)
        self.set_recent_menu()

        if not self.DECK_PATH or self.DECK_PATH == "": 
            self.set_window_empty()
        else:
            if self.init_deck():
                self.set_question()
                self.set_stats()
        gtk.main()
Esempio n. 13
0
    def save(self, button):
        """Saves user notification settings to gconf
        """
        gconf.client_get_default().set_string('/apps/maegios/notify_banner', \
            str(int(self.checkBanner.get_active())))
        gconf.client_get_default().set_string('/apps/maegios/notify_sound', \
            str(int(self.checkSound.get_active())))
        gconf.client_get_default().set_string('/apps/maegios/notify_vibration', \
            str(int(self.checkVibration.get_active())))
        gconf.client_get_default().set_string('/apps/maegios/notify_light', \
            str(int(self.checkLight.get_active())))

        # notify desktop widget that configuration has been changed
        self.toplevel.reload_widget()

        # refresh treeview
        self.toplevel.refresh()

        button.get_toplevel().get_stack().pop(1)

        # configuration note
        note = hildon.hildon_note_new_information(button.get_toplevel(), \
           _(u"Your notification settings have been changed."))
        response = gtk.Dialog.run(note)
Esempio n. 14
0
    def display(self, widget):
        # Create the main window
        self.window = hildon.StackableWindow()
        self.window.set_title(_(u"Notification Settings"))

        self.checkBanner = gtk.CheckButton(label = _(u" Show Banner Popup "))
        self.checkSound = gtk.CheckButton(label = _(u" Play Sound "))
        self.checkVibration = gtk.CheckButton(label = _(u" Vibrate "))
        self.checkLight = gtk.CheckButton(label = _(u" Blink LED Light "))
        
        if int(gconf.client_get_default().get_string('/apps/maegios/notify_banner')) == 1:
            self.checkBanner.set_active(True)
        if int(gconf.client_get_default().get_string('/apps/maegios/notify_sound')) == 1:
            self.checkSound.set_active(True)
        if int(gconf.client_get_default().get_string('/apps/maegios/notify_vibration')) == 1:
            self.checkVibration.set_active(True)
        if int(gconf.client_get_default().get_string('/apps/maegios/notify_light')) == 1:
            self.checkLight.set_active(True)          
        
        
        '''
        self.entryInterval.set_max_length(5)
        self.entryInterval.set_text(gconf.client_get_default().get_string('/apps/maegios/interval'))
        self.entryAttempts = hildon.Entry(3)
        self.entryAttempts.set_max_length(5)
        self.entryAttempts.set_text(gconf.client_get_default().get_string('/apps/maegios/attempts'))
        '''

        self.buttonSave = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | 
                                        gtk.HILDON_SIZE_FINGER_HEIGHT,
                                        hildon.BUTTON_ARRANGEMENT_VERTICAL)
        self.buttonSave.set_label(_(u"Save"))

        vbox = gtk.VBox(True, 1)

        # Banner
        checkBannerHBox = gtk.HBox(False, 0)
        checkBannerHBox.pack_start(self.checkBanner, False, False, 50)
        vbox.pack_start(checkBannerHBox, False, False, 0)

        # Sound
        checkSoundHBox = gtk.HBox(False, 0)
        checkSoundHBox.pack_start(self.checkSound, False, False, 50)
        vbox.pack_start(checkSoundHBox, False, False, 0)

        # Vibration
        checkVibrationHBox = gtk.HBox(False, 0)
        checkVibrationHBox.pack_start(self.checkVibration, False, False, 50)
        vbox.pack_start(checkVibrationHBox, False, False, 0)
        
        # Light
        checkLightHBox = gtk.HBox(False, 0)
        checkLightHBox.pack_start(self.checkLight, False, False, 50)
        vbox.pack_start(checkLightHBox, False, False, 0)        

        buttonBox = gtk.HBox(False, 0)
        buttonBox.pack_start(self.buttonSave, True, True, 50)
        #buttonBox.pack_start(buttonBox, True, True, 50)

        vbox.pack_start(buttonBox, True, False, 0)

        self.window.add(vbox)

        self.buttonSave.connect("clicked", self.save)

        # This call show the window and also add the window to the stack
        self.window.show_all()
Esempio n. 15
0
    def __init__(self):
        global default_config
        hildondesktop.HomePluginItem.__init__(self)
        
        self.config = default_config

        # read config from gconf
        if not gconf.client_get_default().dir_exists('/apps/maegios'):
            gconf.client_get_default().add_dir('/apps/maegios', gconf.CLIENT_PRELOAD_NONE)
            gconf.client_get_default().set_string('/apps/maegios/url', self.config['url'])
            gconf.client_get_default().set_string('/apps/maegios/username', self.config['username'])
            gconf.client_get_default().set_string('/apps/maegios/password', self.config['password'])
            gconf.client_get_default().set_string('/apps/maegios/interval', self.config['interval'])
            gconf.client_get_default().set_string('/apps/maegios/attempts', self.config['attempts'])
            gconf.client_get_default().set_string('/apps/maegios/is_configured', self.config['is_configured'])
            gconf.client_get_default().set_string('/apps/maegios/notify_banner', self.config['notify_banner'])
            gconf.client_get_default().set_string('/apps/maegios/notify_sound', self.config['notify_sound'])
            gconf.client_get_default().set_string('/apps/maegios/notify_vibration', self.config['notify_vibration'])
            gconf.client_get_default().set_string('/apps/maegios/notify_light', self.config['notify_light'])
            
        if gconf.client_get_default().get_string('/apps/maegios/notify_banner') == None:
            gconf.client_get_default().set_string('/apps/maegios/notify_banner', self.config['notify_banner'])    
        if gconf.client_get_default().get_string('/apps/maegios/notify_sound') == None:
            gconf.client_get_default().set_string('/apps/maegios/notify_sound', self.config['notify_sound'])
        if gconf.client_get_default().get_string('/apps/maegios/notify_vibration') == None:
            gconf.client_get_default().set_string('/apps/maegios/notify_vibration', self.config['notify_vibration'])
        if gconf.client_get_default().get_string('/apps/maegios/notify_light') == None:    
            gconf.client_get_default().set_string('/apps/maegios/notify_light', self.config['notify_light'])                        
                        
                        
        # listen for changes to configuration: (this doesn't work for some unknown reason - why?)
        # implemented using sockets with random port provided by os instead
        #self.gconf_client.notify_add('/apps/maegios', self.reload_configuration)   

        self.alpha_channel = True
        self.set_size_request(90, 110)
        self.set_decorated(0)
        self.set_app_paintable(1)
        #self.set_events(gtk.gdk.ALL_EVENTS_MASK) 
        self.set_colormap(self.get_screen().get_rgba_colormap())
        
        self.images = {'OK': '/usr/share/icons/hicolor/64x64/hildon/maegios-ok-64x64.png', 
                       'WARNING': '/usr/share/icons/hicolor/64x64/hildon/maegios-warn-64x64.png', 
                       'CRITICAL': '/usr/share/icons/hicolor/64x64/hildon/maegios-crit-64x64.png',
                       'DISCONNECTED': '/usr/share/icons/hicolor/64x64/hildon/maegios-disconnected-64x64.png'}

        self.event_box = gtk.EventBox()
        self.event_box.set_visible_window(False)       
        
        self.load_config()
        
        # todo: move this out
        if int(gconf.client_get_default().get_string('/apps/maegios/is_configured')) == 1:
            self.update_widget()
            self.button_release_handler = self.event_box.connect("button_release_event",\
            self.start_maegios)             
        else:
            self.label = gtk.Label("Click to\nconfigure\nMaegios")
            self.label.modify_font(pango.FontDescription("11"))     
            self.label.set_justify(gtk.JUSTIFY_CENTER)
            self.label.show()
            self.event_box.add(self.label)
            self.button_release_handler = self.event_box.connect("button_release_event",\
            self.display_nagios_configuration) 
 
        self.event_box.show_all()
        self.add(self.event_box)

        # set up a refresh timer to query Nagios every refreshInterval minutes
        refreshInterval = int(gconf.client_get_default().get_string('/apps/maegios/interval'))
        self.timer = gobject.timeout_add(refreshInterval * 60000, self.refresh)
     
        self.connect("reload_configuration", self.reload_configuration)
        self.connect("expose-event", self.expose)
        self.connect("screen-changed", self.screen_changed)     
        self.connect("destroy", self.quit)
        self.connect("delete_event", self.quit)
             
        # start configuration service listener thread
        self.thread = ConfigurationServiceListener(self)
Esempio n. 16
0
 def __init__(self):
     self.gconf = gconf.client_get_default()
Esempio n. 17
0
    def display(self, widget):
        self.window = hildon.StackableWindow()
        self.window.set_title(_(u"Nagios Configuration"))

        self.labelUrl = gtk.Label(_(u"Nagios URL:"))
        self.labelUrl.set_width_chars(15)
        self.labelUrl.set_alignment(1.0, 0.5)
        self.labelUsername = gtk.Label(_(u"Nagios Username:"******"Nagios Password:"******"Save"))

        self.buttonUndo = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | 
                                        gtk.HILDON_SIZE_FINGER_HEIGHT,
                                        hildon.BUTTON_ARRANGEMENT_VERTICAL)
        self.buttonUndo.set_label(_(u"Clear"))

        self.vbox = gtk.VBox(True, 1)

        # URL
        self.hboxUrl = gtk.HBox(False, 0)
        self.hboxUrl.pack_start(self.labelUrl, False, False, 20)
        self.hboxUrl.pack_start(self.entryUrl, True, True, 20)
        self.vbox.pack_start(self.hboxUrl, False, False, 0)

        # Username
        self.hboxUsername = gtk.HBox(False, 0)
        self.hboxUsername.pack_start(self.labelUsername, False, False, 20)
        self.hboxUsername.pack_start(self.entryUsername, True, True, 20)
        self.vbox.pack_start(self.hboxUsername, False, False, 0)

        # Password
        self.hboxPassword = gtk.HBox(False, 0)
        self.hboxPassword.pack_start(self.labelPassword, False, False, 20)
        self.hboxPassword.pack_start(self.entryPassword, True, True, 20)
        self.vbox.pack_start(self.hboxPassword, False, False, 0)

        self.buttonBox = gtk.HBox(False, 0)
        self.buttonBox.pack_start(self.buttonSave, True, True, 50)
        self.buttonBox.pack_start(self.buttonUndo, True, True, 50)

        self.vbox.pack_start(self.buttonBox, True, False, 0)

        self.window.add(self.vbox)

        self.buttonSave.connect("clicked", self.save)
        self.buttonUndo.connect("clicked", self.undo)

        self.window.show_all()
Esempio n. 18
0
 def load_config(self):
     # load maegios configuration from gconf:
     if gconf.client_get_default().dir_exists('/apps/maegios'):
         self.config['url'] = gconf.client_get_default().get_string('/apps/maegios/url')
         self.config['username'] = gconf.client_get_default().get_string('/apps/maegios/username')
         self.config['password'] = gconf.client_get_default().get_string('/apps/maegios/password')
         self.config['interval'] = gconf.client_get_default().get_string('/apps/maegios/interval')
         self.config['attempts'] = gconf.client_get_default().get_string('/apps/maegios/attempts')
         self.config['is_configured'] = gconf.client_get_default().get_string('/apps/maegios/is_configured')
         self.config['notify_banner'] = gconf.client_get_default().get_string('/apps/maegios/notify_banner')           
         self.config['notify_sound'] = gconf.client_get_default().get_string('/apps/maegios/notify_sound')     
         self.config['notify_vibration'] = gconf.client_get_default().get_string('/apps/maegios/notify_vibration')     
         self.config['notify_light'] = gconf.client_get_default().get_string('/apps/maegios/notify_light')      
Esempio n. 19
0
    def update_widget(self, softUpdate = False):
    
        self.image = gtk.Image()  
        self.image.set_size_request(64, 64) 
        
        hosts = self.get_nagios_data()
        self.hosts = hosts
        
        # notification patterns for N900
        ledPatternWarning = 'PatternBatteryCharging'
        ledPatternCritical = 'PatternError'
        vibratePattern = 'PatternChatAndEmail'
        
        # connect to mce service
        try:
            bus = dbus.SystemBus()
            smsobject = bus.get_object('com.nokia.mce', '/com/nokia/mce/request')
            smsiface = dbus.Interface(smsobject, 'com.nokia.mce.request')      
            dbusConn = True
        except:
            dbusConn = False
        
        # deactivate previous led patterns
        if dbusConn:
            smsiface.req_led_pattern_deactivate(dbus.String(ledPatternCritical))
            smsiface.req_led_pattern_deactivate(dbus.String(ledPatternWarning))
        
        if hosts == False:
            # display disconnected icon
            self.image.set_from_file(self.images['DISCONNECTED'])
            hostStatusString = _(u"Disco'd")
            infoString = ""
        else:
            criticalServices = 0
            warningServices = 0       
            for host in hosts:
                for service in host['services']:
                    if service['status'] == "WARNING":
                        warningServices += 1
                    elif service['status'] == "CRITICAL":
                        criticalServices += 1
            
            ledPattern = str()              
            hostStatusString = str()
            if criticalServices > 0:
                self.image.set_from_file(self.images['CRITICAL'])   
                ledPattern = ledPatternCritical
                if criticalServices > 1:
                    hostStatusString = str(criticalServices) + " " + _(u"Alerts")
                    infoString = str(criticalServices) + " " + _(u"Critical Alerts")
                else:
                    hostStatusString = str(criticalServices) + " " + _(u"Alert")   
                    infoString = str(criticalServices) + " " + _(u"Critical Alert")
            elif warningServices > 0:
                ledPattern = ledPatternWarning
                if warningServices > 1:
                    hostStatusString = str(warningServices) + " " + _(u"Alerts")
                    infoString = str(warningServices) + " " + _(u"Warning Alerts")
                else:
                    hostStatusString = str(warningServices) + " " + _(u"Alert")
                    infoString = str(warningServices) + " " + _(u"Warning Alert")
                self.image.set_from_file(self.images['WARNING'])   
            else:
                self.image.set_from_file(self.images['OK'])   
                hostStatusString = _(u"All Good!")
                infoString = ""
        
        self.label = gtk.Label(hostStatusString)
        self.label.set_justify(gtk.JUSTIFY_CENTER)
        self.label.modify_font(pango.FontDescription("11"))    
        
        if len(infoString) > 0:
            # notify
            if int(gconf.client_get_default().get_string('/apps/maegios/notify_banner')) == 1 and softUpdate == False and dbusConn:
                banner = hildon.hildon_banner_show_information(self, '', \
                "Nagios: %s!" % infoString)
                banner.set_timeout(5000)
                
            if int(gconf.client_get_default().get_string('/apps/maegios/notify_sound')) == 1 and softUpdate == False and dbusConn:
                player = gst.element_factory_make('playbin2', 'myplayer')
                player.set_property('uri', 'file:///usr/share/sounds/ui-new_email.wav')
                player.set_state(gst.STATE_PLAYING)
                            
            if int(gconf.client_get_default().get_string('/apps/maegios/notify_vibration')) == 1 and softUpdate == False and dbusConn:
                smsiface.req_vibrator_pattern_activate(dbus.String(vibratePattern))
            
            if int(gconf.client_get_default().get_string('/apps/maegios/notify_light')) == 1 and dbusConn:
                smsiface.req_led_pattern_activate(dbus.String(ledPattern))
                        
        self.image.show_all()
        self.label.show_all()

        self.vbox = gtk.VBox(False, 0)
        if len(self.event_box.get_children()) > 0:
            self.event_box.remove(self.event_box.get_children()[0])      
              
        self.vbox.set_border_width(12)
        self.vbox.pack_start(self.image, False, False, 0)
        self.vbox.pack_start(self.label, False, False, 5)
        self.vbox.show_all()
        self.event_box.add(self.vbox)
Esempio n. 20
0
 def refresh(self, softUpdate = False):
     refreshInterval = int(gconf.client_get_default().get_string('/apps/maegios/interval'))
     self.timer = gobject.timeout_add(refreshInterval * 60000, self.refresh)
     self.update_widget(softUpdate)                
Esempio n. 21
0
 def __init__(self, hostdata = None):
     global default_config
     
     self.config = default_config
     self.hostdata = hostdata
     
     # read config from gconf
     if not gconf.client_get_default().dir_exists('/apps/maegios'):
         gconf.client_get_default().add_dir('/apps/maegios', gconf.CLIENT_PRELOAD_NONE)
         # update maegios configuration:
         gconf.client_get_default().set_string('/apps/maegios/url', self.config['url'])
         gconf.client_get_default().set_string('/apps/maegios/username', self.config['username'])
         gconf.client_get_default().set_string('/apps/maegios/password', self.config['password'])
         gconf.client_get_default().set_string('/apps/maegios/interval', self.config['interval'])
         gconf.client_get_default().set_string('/apps/maegios/attempts', self.config['attempts'])
         gconf.client_get_default().set_string('/apps/maegios/is_configured', self.config['is_configured'])
         gconf.client_get_default().set_string('/apps/maegios/notify_banner', self.config['notify_banner'])
         gconf.client_get_default().set_string('/apps/maegios/notify_sound', self.config['notify_sound'])
         gconf.client_get_default().set_string('/apps/maegios/notify_vibration', self.config['notify_vibration'])
         gconf.client_get_default().set_string('/apps/maegios/notify_light', self.config['notify_light'])
         
     if gconf.client_get_default().get_string('/apps/maegios/notify_banner') == None:
         gconf.client_get_default().set_string('/apps/maegios/notify_banner', self.config['notify_banner'])    
     if gconf.client_get_default().get_string('/apps/maegios/notify_sound') == None:
         gconf.client_get_default().set_string('/apps/maegios/notify_sound', self.config['notify_sound'])
     if gconf.client_get_default().get_string('/apps/maegios/notify_vibration') == None:
         gconf.client_get_default().set_string('/apps/maegios/notify_vibration', self.config['notify_vibration'])
     if gconf.client_get_default().get_string('/apps/maegios/notify_light') == None:    
         gconf.client_get_default().set_string('/apps/maegios/notify_light', self.config['notify_light'])
         
     # load maegios configuration from gconf:
     if gconf.client_get_default().dir_exists('/apps/maegios'):
         self.config['url'] = gconf.client_get_default().get_string('/apps/maegios/url')
         self.config['username'] = gconf.client_get_default().get_string('/apps/maegios/username')
         self.config['password'] = gconf.client_get_default().get_string('/apps/maegios/password')
         self.config['interval'] = gconf.client_get_default().get_string('/apps/maegios/interval')
         self.config['attempts'] = gconf.client_get_default().get_string('/apps/maegios/attempts')
         self.config['is_configured'] = gconf.client_get_default().get_string('/apps/maegios/is_configured')                    
         self.config['notify_banner'] = gconf.client_get_default().get_string('/apps/maegios/notify_banner')           
         self.config['notify_sound'] = gconf.client_get_default().get_string('/apps/maegios/notify_sound')     
         self.config['notify_vibration'] = gconf.client_get_default().get_string('/apps/maegios/notify_vibration')     
         self.config['notify_light'] = gconf.client_get_default().get_string('/apps/maegios/notify_light')                                          
     self.filter = "new"
Esempio n. 22
0
	def __init__(self):
		#self._fmmsdir = "/apps/fmms/"
		self._iapdir = "/system/osso/connectivity/IAP"
		self.client = gconf.client_get_default()
Esempio n. 23
0
    def create_model(self, filter = "new", hostdata = None):
        lstore = gtk.TreeStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING, gobject.TYPE_STRING)

        data = ["OK", "WARN", "CRIT"]
        hostIcons = ["/usr/share/icons/hicolor/64x64/hildon/maegios-host-ok-64x64.png", 
                     "/usr/share/icons/hicolor/64x64/hildon/maegios-host-warn-64x64.png", 
                     "/usr/share/icons/hicolor/64x64/hildon/maegios-host-crit-64x64.png"]

        serviceIcons = ["/usr/share/icons/hicolor/64x64/hildon/maegios-service-ok-64x64.png", 
                        "/usr/share/icons/hicolor/64x64/hildon/maegios-service-warn-64x64.png", 
                        "/usr/share/icons/hicolor/64x64/hildon/maegios-service-crit-64x64.png",

                        "/usr/share/icons/hicolor/64x64/hildon/maegios-disconnected-64x64.png"]
        remainingAttempts = int(gconf.client_get_default().get_string('/apps/maegios/attempts'))

        # Use data from the widget if available:
        if hostdata != None and (filter == "new" or filter == "problems"):
            hosts = hostdata
        else:
            # Attempt to retrieve data from nagios
            while remainingAttempts > 0:
                #print "connection attempts [app]: %d" % remainingAttempts
                try:
                    # Load and parse nagios data
                    if filter == "new":
                        parser = NagiosParser(only_active = 1)
                    else:
                        parser = NagiosParser()
                    connector = NagiosConnector(self)
                    if filter == "new" or filter == "problems":
                        parser.feed(connector.get_down_hosts())
                    elif filter == "all":
                        parser.feed(connector.get_all_hosts())
                    parser.close()
                    hosts = parser.get_hosts()
                    break
                except:
                    remainingAttempts -= 1
                    time.sleep(0.1)
                
        if remainingAttempts == 0:
            liter = lstore.append(None)
            lstore.set(liter, 2, "", 1, _(u"Disconnected"), 0, self.set_pix(serviceIcons[3]))        
        else:
            if len(hosts) == 0:
                liter = lstore.append(None)
                nothingFoundString = str()
                if filter == "new":
                    nothingFoundString = _(u"All good!")
                    nothingFoundInfo = _(u"(no new alerts)")
                elif filter == "all":
                    nothingFoundString = _(u"No services or hosts found in Nagios")
                    nothingFoundInfo = ""
                elif filter == "problems":
                    nothingFoundString = _(u"No problems with services or hosts found in Nagios")
                    nothingFoundInfo = ""
                lstore.set(liter, 2, nothingFoundInfo, 1, nothingFoundString, 0, \
                self.set_pix(serviceIcons[0]))
            else:
                iconlist = []
                for host in hosts:
                    criticalServices = 0
                    warningServices = 0
                    for service in host['services']:
                        if service['status'] == "CRITICAL":
                            criticalServices += 1
                        elif service['status'] == "WARNING":
                            warningServices += 1
                            
                    hostStatusString = str()
                    if warningServices > 0:
                        hostStatusString = _(u"%d WARNING") % warningServices
                        hostItemIcon = hostIcons[1] 
                    elif criticalServices > 0:
                        hostStatusString = _(u"%d CRITICAL") % criticalServices
                        hostItemIcon = hostIcons[2]
                    else:
                        if len(host['services']) > 0:
                            hostStatusString = _(u"%d OK") % len(host['services'])
                            hostItemIcon = hostIcons[0]
                        else:
                            if host['host']['status'] == 'UP':
                                hostItemIcon = hostIcons[0]  
                            else:
                                hostItemIcon = hostIcons[2]  
                            
                    iconlist.append([host['host']['hostname'], hostItemIcon, hostStatusString])

                for item in iconlist:
                    liter = lstore.append(None)
                    lstore.set(liter, 2, item[2], 1, item[0], 0, self.set_pix(item[1]))
                    for host in hosts:
                        if host['host']['hostname'] == item[0]:
                            for service in host['services']:
                                statusIcon = serviceIcons[0]
                                if service['status'] == 'WARNING':
                                    statusIcon = serviceIcons[1]
                                elif service['status'] == 'CRITICAL':
                                    statusIcon = serviceIcons[2]
                                lstore.append(liter, [self.set_pix(statusIcon), \
                                "    %s" % service['name'], service['info']])

        return lstore