Exemple #1
0
def getDetailsTree(request, hostname):
    #Entering in any platform an collect tree info
    logger.debug('Collecting platform trees')
    data = []
    content = {
        "isFolder": True,
        "expand": True,
        "title": hostname,
        "key": hostname,
        "icon": "server.png",
        "detailsEnabled": "true",
        'url': reverse('server_inventory_details',
                       kwargs={'hostname': hostname})
    }
    children = []
    tree_modules = platforms.extract(ServerTree)
    if tree_modules:
        for current in tree_modules:
            platform_data = current.getDetailsTree(hostname)
            if platform_data:
                children.append(platform_data)

    content['children'] = children
    data.append(content)
    return HttpResponse(json.dumps(data))
Exemple #2
0
 def refresh_server_inventory(self, user):
     logger.info("Calling Refresh Inventory")
     try: 
         updates_defined = platforms.extract(UpdatePlatform)
         result = send_task("webui.serverstatus.tasks.server_inventory", [user, updates_defined])    
         json_data = json.dumps({'UUID': result.task_id, 'taskname':"webui.serverstatus.tasks.server_inventory"})
         return json_data
     except Exception, err:
         logger.error('ERROR: ' + str(err))
Exemple #3
0
 def refresh_server_inventory(self, user):
     logger.info("Calling Refresh Inventory")
     try: 
         updates_defined = platforms.extract(UpdatePlatform)
         result = send_task("webui.serverstatus.tasks.server_inventory", [user, updates_defined])    
         json_data = json.dumps({'UUID': result.task_id, 'taskname':"webui.serverstatus.tasks.server_inventory"})
         return json_data
     except Exception, err:
         logger.error('ERROR: ' + str(err))
Exemple #4
0
 def get_context(self):
     super_context = super(self.__class__,self).get_context()
     applications = []
     app_modules = platforms.extract(Application)
     if app_modules:
         for current_module in app_modules:
             applications_list = current_module.getApplications(self.user)
             if applications_list:
                 applications.extend(applications_list)
     widget_context = {"applications":applications}
     return dict(super_context.items() + widget_context.items())
Exemple #5
0
 def get_context(self):
     super_context = super(self.__class__, self).get_context()
     applications = []
     app_modules = platforms.extract(Application)
     if app_modules:
         for current_module in app_modules:
             applications_list = current_module.getApplications(self.user)
             if applications_list:
                 applications.extend(applications_list)
     widget_context = {"applications": applications}
     return dict(super_context.items() + widget_context.items())
Exemple #6
0
def send_server_inventory_email():
    alert_db = Alert.objects.get(name='ServerListMailAlert')
    if alert_db.enabled:
        htmly = get_template('alerting/serveremail.html')
        #Extract first level puppet class for user.
        for user in alert_db.users.all():
            servers_for_mail = []
            first_level_classes = get_objects_for_user(
                user, 'access_puppet_class', PuppetClass).filter(enabled=True,
                                                                 level=0)
            second_level_classes = get_objects_for_user(
                user, 'access_puppet_class', PuppetClass).filter(enabled=True,
                                                                 level=1)
            for first_level_class in first_level_classes:
                for second_level_class in second_level_classes:
                    server_path = '/' + first_level_class.name + '/' + second_level_class.name
                    app_modules = platforms.extract(Application)
                    applications = []
                    if app_modules:
                        for current_module in app_modules:
                            applications_list = current_module.getApplicationsPath(
                                user, server_path)
                            if applications_list:
                                applications.extend(applications_list)
                    if len(applications) > 0:
                        servers_for_mail.append({
                            'first_level_class':
                            first_level_class.name,
                            'second_level_class':
                            second_level_class.name,
                            "applications":
                            applications
                        })
            if len(servers_for_mail) > 0:
                d = Context({'classed_servers': servers_for_mail})

                try:
                    from_email = CONF.get('webui', 'alerting.from_mail')
                except:
                    logger.warn(
                        "No from_mail configured in your webui config file. Using default"
                    )
                    from_email = '*****@*****.**'
                subject = alert_db.mail_subjet
                html_content = htmly.render(d)
                msg = EmailMultiAlternatives(subject, "Need HTML", from_email,
                                             [user.email])
                msg.attach_alternative(html_content, "text/html")
                msg.send()
            else:
                logger.info(
                    "Mail for user %s won't be send. No applications found!" %
                    user.username)
Exemple #7
0
def server_inventory(user, updates_defined=None):
    if not updates_defined:
        logger.debug("Calling without updates. Trying to retrieve them")
        updates_defined = platforms.extract(UpdatePlatform)
        
    if updates_defined:
        total_updates = len(updates_defined)
        i = 0
        for current_update in updates_defined:
            current_update.inventoryUpdate(user, False)
            i = i + 1
            server_inventory.update_state(state="PROGRESS", meta={"current": i, "total": total_updates})
    else:
        logger.warn("No update defined for installed platforms")
Exemple #8
0
def getDetailsTree(request, hostname):
    #Entering in any platform an collect tree info
    logger.debug('Collecting platform trees')
    data = []
    content = {"isFolder": True, "expand": True, "title": hostname, "key":hostname, "icon":"server.png", "detailsEnabled":"true", 'url': reverse('server_inventory_details', kwargs={'hostname':hostname})}
    children = []
    tree_modules = platforms.extract(ServerTree)
    if tree_modules:
        for current in tree_modules:
            platform_data = current.getDetailsTree(hostname)
            if platform_data:
                children.append(platform_data)
        
    content['children'] = children
    data.append(content)
    return HttpResponse(json.dumps(data))
Exemple #9
0
 def render(self, args):
     logger.debug('Calling override render for ' + __name__)
     template_instance = get_template(self.template)
     data = self.get_context()
     appname = args
     data.update(widget=self, user=self.user, appname=appname)
     
     applications = []
     app_modules = platforms.extract(Application)
     if app_modules:
         for current_module in app_modules:
             applications_list = current_module.getAppliInfo(self.user, appname)
             if applications_list:
                 applications.extend(applications_list)
             
     data.update(applications=applications)
     return template_instance.render(Context(data))
Exemple #10
0
def send_server_inventory_email():
    alert_db = Alert.objects.get(name="ServerListMailAlert")
    if alert_db.enabled:
        htmly = get_template("alerting/serveremail.html")
        # Extract first level puppet class for user.
        for user in alert_db.users.all():
            servers_for_mail = []
            first_level_classes = get_objects_for_user(user, "access_puppet_class", PuppetClass).filter(
                enabled=True, level=0
            )
            second_level_classes = get_objects_for_user(user, "access_puppet_class", PuppetClass).filter(
                enabled=True, level=1
            )
            for first_level_class in first_level_classes:
                for second_level_class in second_level_classes:
                    server_path = "/" + first_level_class.name + "/" + second_level_class.name
                    app_modules = platforms.extract(Application)
                    applications = []
                    if app_modules:
                        for current_module in app_modules:
                            applications_list = current_module.getApplicationsPath(user, server_path)
                            if applications_list:
                                applications.extend(applications_list)
                    if len(applications) > 0:
                        servers_for_mail.append(
                            {
                                "first_level_class": first_level_class.name,
                                "second_level_class": second_level_class.name,
                                "applications": applications,
                            }
                        )
            if len(servers_for_mail) > 0:
                d = Context({"classed_servers": servers_for_mail})

                try:
                    from_email = CONF.get("webui", "alerting.from_mail")
                except:
                    logger.warn("No from_mail configured in your webui config file. Using default")
                    from_email = "*****@*****.**"
                subject = alert_db.mail_subjet
                html_content = htmly.render(d)
                msg = EmailMultiAlternatives(subject, "Need HTML", from_email, [user.email])
                msg.attach_alternative(html_content, "text/html")
                msg.send()
            else:
                logger.info("Mail for user %s won't be send. No applications found!" % user.username)
Exemple #11
0
    def render(self, args):
        logger.debug('Calling override render for ' + __name__)
        template_instance = get_template(self.template)
        data = self.get_context()
        appname = args
        data.update(widget=self, user=self.user, appname=appname)

        applications = []
        app_modules = platforms.extract(Application)
        if app_modules:
            for current_module in app_modules:
                applications_list = current_module.getAppliInfo(
                    self.user, appname)
                if applications_list:
                    applications.extend(applications_list)

        data.update(applications=applications)
        return template_instance.render(Context(data))
Exemple #12
0
def server_inventory(user, updates_defined=None):
    if not updates_defined:
        logger.debug("Calling without updates. Trying to retrieve them")
        updates_defined = platforms.extract(UpdatePlatform)

    if updates_defined:
        total_updates = len(updates_defined)
        i = 0
        for current_update in updates_defined:
            current_update.inventoryUpdate(user, False)
            i = i + 1
            server_inventory.update_state(state="PROGRESS",
                                          meta={
                                              "current": i,
                                              "total": total_updates
                                          })
    else:
        logger.warn("No update defined for installed platforms")