当前位置: 首页>>代码示例>>Python>>正文


Python DBMysql.create_update_query方法代码示例

本文整理汇总了Python中shinken.db_mysql.DBMysql.create_update_query方法的典型用法代码示例。如果您正苦于以下问题:Python DBMysql.create_update_query方法的具体用法?Python DBMysql.create_update_query怎么用?Python DBMysql.create_update_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shinken.db_mysql.DBMysql的用法示例。


在下文中一共展示了DBMysql.create_update_query方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Ndodb_Mysql_broker

# 需要导入模块: from shinken.db_mysql import DBMysql [as 别名]
# 或者: from shinken.db_mysql.DBMysql import create_update_query [as 别名]

#.........这里部分代码省略.........
                    val = f(val)
                new_name = mapping[prop]["name"]
                to_add.append((new_name, val))
                to_del.append(prop)
        for prop in to_del:
            del new_b.data[prop]
        for (name, val) in to_add:
            new_b.data[name] = val
        query = self.db.create_insert_query("programstatus", new_b.data)
        return [query_delete_instance, query_instance, query]

    # TODO : fill nagios_instances
    def manage_update_program_status_brok(self, b):
        new_b = copy.deepcopy(b)
        to_del = ["instance_name", "command_file"]
        to_add = []
        mapping = self.mapping["program_status"]
        for prop in new_b.data:
            # ex : 'name' : 'program_start_time', 'transform'
            if prop in mapping:
                # print "Got a prop to change", prop
                val = new_b.data[prop]
                if mapping[prop]["transform"] is not None:
                    f = mapping[prop]["transform"]
                    val = f(val)
                new_name = mapping[prop]["name"]
                to_add.append((new_name, val))
                to_del.append(prop)
        for prop in to_del:
            del new_b.data[prop]
        for (name, val) in to_add:
            new_b.data[name] = val
        where_clause = {"instance_id": new_b.data["instance_id"]}
        query = self.db.create_update_query("programstatus", new_b.data, where_clause)
        return [query]

    # A host have just be create, database is clean, we INSERT it
    def manage_initial_host_status_brok(self, b):
        # new_b = copy.deepcopy(b)

        data = b.data

        # First add to nagios_objects
        objects_data = {
            "instance_id": data["instance_id"],
            "objecttype_id": 1,
            "name1": data["host_name"],
            "is_active": data["active_checks_enabled"],
        }
        object_query = self.db.create_insert_query("objects", objects_data)
        self.db.execute_query(object_query)

        host_id = self.get_host_object_id_by_name(data["host_name"])

        # print "DATA:", data
        hosts_data = {
            "host_id": data["id"],
            "instance_id": data["instance_id"],
            "host_object_id": host_id,
            "alias": data["alias"],
            "display_name": data["display_name"],
            "address": data["address"],
            "failure_prediction_options": "0",
            "check_interval": data["check_interval"],
            "retry_interval": data["retry_interval"],
            "max_check_attempts": data["max_check_attempts"],
开发者ID:wAmpIre,项目名称:shinken,代码行数:70,代码来源:ndodb_mysql_broker.py

示例2: Ndodb_Mysql_broker

# 需要导入模块: from shinken.db_mysql import DBMysql [as 别名]
# 或者: from shinken.db_mysql.DBMysql import create_update_query [as 别名]

#.........这里部分代码省略.........
                to_del.append(prop)
        for prop in to_del:
            del new_b.data[prop]
        for (name, val) in to_add:
            new_b.data[name] = val
        query = self.db.create_insert_query('programstatus', new_b.data)
        return [query_delete_instance, query_instance, query]



    # TODO : fill nagios_instances
    def manage_update_program_status_brok(self, b):
        new_b = copy.deepcopy(b)
        to_del = ['instance_name', 'command_file', 'check_external_commands', 'check_service_freshness',
                  'check_host_freshness']
        to_add = []
        mapping = self.mapping['program_status']
        for prop in new_b.data:
            # ex : 'name' : 'program_start_time', 'transform'
            if prop in mapping:
                #print "Got a prop to change", prop
                val = new_b.data[prop]
                if mapping[prop]['transform'] is not None:
                    f = mapping[prop]['transform']
                    val = f(val)
                new_name = mapping[prop]['name']
                to_add.append((new_name, val))
                to_del.append(prop)
        for prop in to_del:
            del new_b.data[prop]
        for (name, val) in to_add:
            new_b.data[name] = val
        where_clause = {'instance_id' : new_b.data['instance_id']}
        query = self.db.create_update_query('programstatus', new_b.data, where_clause)
        return [query]



    # A host have just be create, database is clean, we INSERT it
    def manage_initial_host_status_brok(self, b):
        
        data = b.data

        # First add to nagios_objects
        objects_data = {'instance_id' : data['instance_id'], 'objecttype_id' : 1,
                        'name1' : data['host_name'], 'is_active' : data['active_checks_enabled']
                        }
        object_query = self.db.create_insert_query('objects', objects_data)
        self.db.execute_query(object_query)

        host_id = self.get_host_object_id_by_name_sync(data['host_name'],data['instance_id'])

        #print "DATA:", data
        hosts_data = { 'instance_id' : data['instance_id'],
                      'host_object_id' : host_id, 'alias' : data['alias'],
                      'display_name' : data['display_name'], 'address' : data['address'],
                      'failure_prediction_options' : '0', 'check_interval' : data['check_interval'],
                      'retry_interval' : data['retry_interval'], 'max_check_attempts' : data['max_check_attempts'],
                      'first_notification_delay' : data['first_notification_delay'], 'notification_interval' : data['notification_interval'],
                      'flap_detection_enabled' : data['flap_detection_enabled'], 'low_flap_threshold' : data['low_flap_threshold'],
                      'high_flap_threshold' : data['high_flap_threshold'], 'process_performance_data' : data['process_perf_data'],
                      'freshness_checks_enabled' : data['check_freshness'], 'freshness_threshold' : data['freshness_threshold'],
                      'passive_checks_enabled' : data['passive_checks_enabled'], 'event_handler_enabled' : data['event_handler_enabled'],
                      'active_checks_enabled' : data['active_checks_enabled'], 'notifications_enabled' : data['notifications_enabled'],
                      'obsess_over_host' : data['obsess_over_host'], 'notes' : data['notes'], 'notes_url' : data['notes_url'],
            }
开发者ID:bs-github,项目名称:shinken,代码行数:70,代码来源:ndodb_mysql_broker.py

示例3: Glpidb_broker

# 需要导入模块: from shinken.db_mysql import DBMysql [as 别名]
# 或者: from shinken.db_mysql.DBMysql import create_update_query [as 别名]

#.........这里部分代码省略.........
                new_brok.data[name] = val
        else:
            print "No preprocess type", brok.type
            print brok.data
        return new_brok



    #Get a brok, parse it, and put in in database
    #We call functions like manage_ TYPEOFBROK _brok that return us queries
    def manage_brok(self, b):
        type = b.type
        # To update check in glpi_plugin_monitoring_hosts
        manager = 'manage_'+type+'up_brok'
        if hasattr(self, manager):
            new_b = self.preprocess(type, b, 0)
            f = getattr(self, manager)
            queries = f(new_b)
            #Ok, we've got queries, now : run them!
            for q in queries :
                self.db_backend.execute_query(q)
        manager = 'manage_'+type+'_brok'
        if hasattr(self, manager):
            new_b = self.preprocess(type, b, '1')
            if 'host_name' in new_b.data:
               if 'plugin_monitoring_services_id' not in new_b.data:
                  return
            f = getattr(self, manager)
            queries = f(new_b)
            #Ok, we've got queries, now : run them!
            for q in queries :
                self.db_backend.execute_query(q)
            return


    #Host result
    #def manage_host_check_result_brok(self, b):
        #logger.info("GLPI : data in DB %s " % b)
        #b.data['date'] = time.strftime('%Y-%m-%d %H:%M:%S')
        #query = self.db_backend.create_insert_query('glpi_plugin_monitoring_serviceevents', b.data)
        #return [query]


    #Host result
    #def manage_host_check_resultup_brok(self, b):
        #logger.info("GLPI : data in DB %s " % b)
        #new_data = copy.deepcopy(b.data)
        #new_data['last_check'] = time.strftime('%Y-%m-%d %H:%M:%S')
        #new_data['id'] = b.data['plugin_monitoring_services_id']
        #del new_data['plugin_monitoring_services_id']
        #del new_data['perf_data']
        #del new_data['output']
        #del new_data['latency']
        #del new_data['execution_time']
        #where_clause = {'id' : new_data['id']}
        #query = self.db_backend.create_update_query('glpi_plugin_monitoring_services', new_data, where_clause)
        #return [query]

    #Service result
    def manage_service_check_result_brok(self, b):
        #logger.info("GLPI : data in DB %s " % b)
        try:
            b.data['plugin_monitoring_servicescatalogs_id']
            return ''
        except:
            b.data['date'] = time.strftime('%Y-%m-%d %H:%M:%S')
            #print "Add event service : ", b.data
            query = self.db_backend.create_insert_query('glpi_plugin_monitoring_serviceevents', b.data)
            return [query]
        return ''

    #Service result
    def manage_service_check_resultup_brok(self, b):
        """If a host is defined locally (in shinken) and not in GLPI,
           we must not edit GLPI datas !
        """
        if 'plugin_monitoring_servicescatalogs_id' not in b.data and\
           'plugin_monitoring_services_id'         not in b.data:
            return list()

        logger.info("GLPI : data in DB %s " % b.data)
        new_data = copy.deepcopy(b.data)
        new_data['last_check'] = time.strftime('%Y-%m-%d %H:%M:%S')
        del new_data['perf_data']
        del new_data['output']
        del new_data['latency']
        del new_data['execution_time']
        try:
            new_data['id'] = b.data['plugin_monitoring_servicescatalogs_id']
            del new_data['plugin_monitoring_servicescatalogs_id']
            table = 'glpi_plugin_monitoring_servicescatalogs'
        except:
            new_data['id'] = b.data['plugin_monitoring_services_id']
            del new_data['plugin_monitoring_services_id']
            table = 'glpi_plugin_monitoring_services'

        where_clause = {'id' : new_data['id']}
        #print "Update service : ", new_data
        query = self.db_backend.create_update_query(table, new_data, where_clause)
        return [query]
开发者ID:Morkxy,项目名称:shinken,代码行数:104,代码来源:glpidb_broker.py

示例4: Glpidb_broker

# 需要导入模块: from shinken.db_mysql import DBMysql [as 别名]
# 或者: from shinken.db_mysql.DBMysql import create_update_query [as 别名]

#.........这里部分代码省略.........
                self.record_availability(host_name, service_description, b)

            if host_name in self.hosts_cache and self.hosts_cache[host_name]['items_id'] is not None:
                if service_id in self.services_cache and self.services_cache[service_id]['items_id'] is not None:
                    start = time.time()
                    self.record_service_check_result(b)
                    logger.debug("[glpidb] service check result: %s, %d seconds", service_id, time.time() - start)

        return

    ## Host result
    def record_host_check_result(self, b):
        host_name = b.data['host_name']
        host_cache = self.hosts_cache[host_name]
        logger.debug("[glpidb] record host check result: %s: %s", host_name, b.data)

        # Escape SQL fields ...
        # b.data['output'] = MySQLdb.escape_string(b.data['output'])
        # b.data['long_output'] = MySQLdb.escape_string(b.data['long_output'])
        # b.data['perf_data'] = MySQLdb.escape_string(b.data['perf_data'])

        if self.update_hosts:
            data = {}
            data['event'] = ("%s \n %s", b.data['output'], b.data['long_output']) if (len(b.data['long_output']) > 0) else b.data['output']
            data['state'] = b.data['state']
            data['state_type'] = b.data['state_type']
            data['last_check'] = datetime.datetime.fromtimestamp( int(b.data['last_chk']) ).strftime('%Y-%m-%d %H:%M:%S')
            data['perf_data'] = b.data['perf_data']
            data['latency'] = b.data['latency']
            data['execution_time'] = b.data['execution_time']
            data['is_acknowledged'] = '1' if b.data['problem_has_been_acknowledged'] else '0'

            where_clause = {'items_id': host_cache['items_id'], 'itemtype': host_cache['itemtype']}
            query = self.db_backend.create_update_query('glpi_plugin_monitoring_hosts', data, where_clause)
            try:
                self.db_backend.execute_query(query)
            except Exception as exp:
                logger.error("[glpidb] error '%s' when executing query: %s", exp, query)

        # Update acknowledge table if host becomes UP
        #if self.update_acknowledges and b.data['state_id'] == 0 and b.data['last_state_id'] != 0:
        # Update acknowledge table if host is UP
        if self.update_acknowledges and b.data['state_id'] == 0:
            data = {}
            data['end_time'] = datetime.datetime.fromtimestamp( int(b.data['last_chk']) ).strftime('%Y-%m-%d %H:%M:%S')
            data['expired'] = '1'

            where_clause = {'items_id': host_cache['items_id'], 'itemtype': "PluginMonitoringHost"}
            query = self.db_backend.create_update_query('glpi_plugin_monitoring_acknowledges', data, where_clause)
            logger.debug("[glpidb] acknowledge query: %s", query)
            try:
                self.db_backend.execute_query(query)
            except Exception as exp:
                logger.error("[glpidb] error '%s' when executing query: %s", exp, query)

    ## Service result
    def record_service_check_result(self, b):
        host_name = b.data['host_name']
        service_description = b.data['service_description']
        service_id = host_name+"/"+service_description
        service_cache = self.services_cache[service_id]
        logger.debug("[glpidb] service check result: %s: %s", service_id, b.data)

        # Escape SQL fields ...
        # b.data['output'] = MySQLdb.escape_string(b.data['output'])
        # b.data['long_output'] = MySQLdb.escape_string(b.data['long_output'])
开发者ID:shinken-debian-modules,项目名称:shinken-mod-glpidb,代码行数:70,代码来源:module.py


注:本文中的shinken.db_mysql.DBMysql.create_update_query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。