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


Python OssimDB.exec_query方法代码示例

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


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

示例1: __init__

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
  def __init__ (self, conf, id):
    self.__id = id
    self.__default = {}
    self.__ops = {}
    logger.info ("Setting up new WS handler for id '%s'" % id)

    # Read the configuration from the database.
    db = OssimDB (conf[VAR_DB_HOST], "alienvault", conf[VAR_DB_USER], conf[VAR_DB_PASSWORD])
    db.connect()
    # Sanitize the id param. Exactly we need 32 hex characters
    if re.match(r'^[a-fA-F0-9]{32}$',self.__id) == None:
        raise Exception('Bad  webservice id')
    data = db.exec_query ("SELECT HEX(id), type, name, url, namespace, user, pass FROM alienvault.webservice WHERE id = UNHEX('%s')" % self.__id)
    if data != []:
      ws_config = data[0]
    else:
      raise Exception('Id %s does not match a valid webservice' % id)

    ws_default = db.exec_query ("SELECT field, value FROM alienvault.webservice_default WHERE ws_id = UNHEX('%s')" % self.__id)
    if ws_default != []:
      for item in ws_default:
        self.__default[item['field']] = item['value']

    ws_oper = db.exec_query ("SELECT op, type, attrs FROM alienvault.webservice_operation WHERE ws_id = UNHEX('%s')" % self.__id)
    if ws_oper == []:
      raise Exception('Id %s does not match a valid webservice' % id)

    for item in ws_oper:
      self.__ops[item['type']] = {'op': item['op'], 'attrs': [x.replace(' ', '') for x in item['attrs'].split(',')]}

    # Connect to the WS.
    self.__server = Client(ws_config['url'])

    # Authenticate if needed (This may be Remedy specific!!!)
    authinfo_field = ''
    username_field = ''
    password_field = ''
    authentication_field = ''
    locale_field = ''
    timezone_field = ''

    try:
      auth_op = self.__ops['auth']
    except KeyError:
      pass
    else:
      authinfo_field = auth_op['op']
      [username_field, password_field, authentication_field, locale_field, timezone_field] = auth_op['attrs']

      token = self.__server.factory.create(authinfo_field)
      token.__setitem__(username_field, ws_config['user'])
      token.__setitem__(password_field, ws_config['pass'])
#      token.__setitem__(authentication_field, ws_config['auth'])
#      token.__setitem__(locale_field, ws_config['locale'])
#      token.__setitem__(timezone_field, ws_config['tz'])

      self.__server.set_options(soapheaders=token)
开发者ID:jackpf,项目名称:ossim-arc,代码行数:59,代码来源:DoWS.py

示例2: _get_db_conf

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
    def _get_db_conf(self):

        # Now, complete config info from Ossim database
        db = OssimDB(self[VAR_DB_HOST], self[VAR_DB_SCHEMA], self[VAR_DB_USER], self[VAR_DB_PASSWORD])
        db.connect()
        #Reads all the frameworkd configuration values.
        query = "select * from config"
        fmk_table_values = db.exec_query(query)
        for row in fmk_table_values:
            self._conf[row['conf']] = row['value']

        query = ''
        if not self._conf.has_key(VAR_KEY_FILE):
            self._conf[VAR_KEY_FILE] = '/etc/ossim/framework/db_encryption_key'
        keyfile = self._conf[VAR_KEY_FILE]
        useEncryption = False
        if os.path.isfile(keyfile):
            config = ConfigParser.ConfigParser()
            keyfile_fd= open(keyfile,'r')
            try:
                config.readfp(keyfile_fd)
                self._conf[VAR_KEY] = config.get('key-value', 'key')
                useEncryption = True
            except Exception, e:
                logger.error("Invalid key file: %s" % str(e))
            finally:
开发者ID:jackpf,项目名称:ossim-arc,代码行数:28,代码来源:OssimConf.py

示例3: get_nets

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
    def get_nets(self, netgroups, nets):
        netgroups_l = netgroups.split(",")
        nets_l = []
        if not nets == "":
            nets_l = nets.split(",")
        net_list = []

        tmp_conf = OssimConf (Const.CONFIG_FILE)
        tmp_conn = None
        tmp_conn = OssimDB()
        tmp_conn.connect ( tmp_conf["ossim_host"],
                              tmp_conf["ossim_base"],
                              tmp_conf["ossim_user"],
                              tmp_conf["ossim_pass"])
        for group in netgroups_l:
            self.__debug(group)
            query = "SELECT * FROM net_group_reference where net_group_name='%s'" % group
            hash = tmp_conn.exec_query(query)
            for row in hash:
                if not row["net_name"] in net_list:
                    net_list.append(row["net_name"])
        for net in nets_l:
            if not net in net_list:
                net_list.append(net)
        tmp_conn.close()
        return net_list
开发者ID:cterron,项目名称:OSSIM,代码行数:28,代码来源:DoNessus.py

示例4: get_sheduler_list_by_id

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
    def get_sheduler_list_by_id (self, id, type) :
        tmp_conf = OssimConf (Const.CONFIG_FILE)
        tmp_conn = None
        self.__debug("Getting %s from policy id %d" % (type,int(id)))
        list = []
        tmp_conn = OssimDB()
        tmp_conn.connect ( tmp_conf["ossim_host"],
                              tmp_conf["ossim_base"],
                              tmp_conf["ossim_user"],
                              tmp_conf["ossim_pass"])

        query = "SELECT * FROM plugin_scheduler_%s_reference where plugin_scheduler_id = %d" % (type,int(id))
        hash = tmp_conn.exec_query(query)

        if type == "host":
            col = "ip"
        else:
            col = "%s_name" % type

        for row in hash:
            list.append(row[col])

        print list

        tmp_conn.close()
        return list
开发者ID:cterron,项目名称:OSSIM,代码行数:28,代码来源:DoNessus.py

示例5: make_nagios_changes

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
    def make_nagios_changes(self):
        port = None
        db = OssimDB()
        db.connect (self._tmp_conf["ossim_host"],
                self._tmp_conf["ossim_base"],
                self._tmp_conf["ossim_user"],
                self._tmp_conf["ossim_pass"])
        query="select port from host_services where (protocol=6 or protocol=0) and nagios=1 group by port"
        services=db.exec_query(query)

        path = os.path.join(self._tmp_conf['nagios_cfgs'], "host-services")

        for fi in os.listdir(path):
            os.remove(os.path.join(path, fi))

        path = os.path.join(self._tmp_conf['nagios_cfgs'], "hostgroup-services")

        for fi in os.listdir(path):
            os.remove(os.path.join(path, fi))

        i = 0

        for port in services:
            i+=1
            query = "select h.hostname, hs.service_type from host_services hs, host_scan h_sc, host h where (hs.protocol=6 or hs.protocol=0) and hs.port=%s and hs.ip=h_sc.host_ip and h_sc.plugin_id=2007 and hs.nagios=1 and h.ip=inet_ntoa(hs.ip) group by h.ip order by h.ip" % port['port']
            hosts = db.exec_query(query)
            list = ""
            for host in hosts:
                if list != "":
                    list += ","

                list += host['hostname']

            if list != "":
                k = nagios_host_service(list, port['port'], host['service_type'], "check_tcp!%d" % port['port'], "0", self._tmp_conf)
                k.select_command()
                k.write()

                hg = nagios_host_group_service(self.serv_port(port['port']),self.serv_name(port['port']),list,self._tmp_conf)
                hg.write()

        if port is not None and port in services:
            logger.debug("Changes where applied! Reloading Nagios config.")
            self.reload_nagios()

        db.close()
开发者ID:cterron,项目名称:OSSIM,代码行数:48,代码来源:DoNagios.py

示例6: _get_db_conf

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
    def _get_db_conf(self):

        # Now, complete config info from Ossim database
        #
        from OssimDB import OssimDB
        db = OssimDB()
        db.connect(self["ossim_host"], 
                   self["ossim_base"], 
                   self["ossim_user"],
                   self["ossim_pass"])
        query = ''
        useEncryption = False
        if self["encryptionKey"]:
            query = "SELECT * FROM config where conf not like '%%_pass%%'"
            useEncryption = True
        else:
            query = "SELECT * FROM config"
            
        hash = db.exec_query(query)
        for row in hash:
            # values declared at config file override the database ones
            if row["conf"] not in self._conf:
                self[row["conf"]] = row["value"]
                
        #Now read pass
        nones_list = [] 
        if useEncryption: 
            logger.debug("using key: %s" % self['encryptionKey'])
            hash = db.exec_query("SELECT *, AES_DECRYPT(value,'%s') as dvalue FROM config where conf like '%%_pass%%'" % self["encryptionKey"])
            
            for row in hash:
                # values declared at config file override the database ones
                if row["conf"] not in self._conf:
                    logger.debug("PASSWD Row: %s Value:%s " %(row["conf"],row["dvalue"]))
                    if row["dvalue"]is not None:
                        self[row["conf"]] = row["dvalue"]
                    else:
                        nones_list.append(row["conf"])
            if len(nones_list) > 0:
                logger.debug("Reading without decryption....")
                hash = db.exec_query("SELECT * FROM config where conf like '%%_pass%%'")
                for row in hash:
                    self[row["conf"]] = row["value"]
                    logger.debug("Reading pass without decrypt Row: %s Value:%s " %(row["conf"],row["value"]))
            
        db.close()
开发者ID:cterron,项目名称:OSSIM,代码行数:48,代码来源:OssimConf.py

示例7: __init__

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
class ControlManager:
    def __init__(self, conf):
        logger.debug("Initialising ControlManager...")

        self.control_agents = {}
        self.transaction_map = {}
        self.__myDB = OssimDB()
        self.__myDB_connected = False
        self.__myconf = conf
        self.__transaction_timeout = 60
        self.__ntop_apache_manager = ApacheNtopProxyManager(conf)
        self.__control = DoControl(self)
        self.__control.start()
        self.__ntop_configuration_checked = False
        self.__mutexRquest = Lock()


    def refreshAgentCache(self, requestor, agent_id,agent_name):
        if not self.__myDB_connected:
            self.__myDB.connect (self.__myconf["ossim_host"],
            self.__myconf["ossim_base"],
            self.__myconf["ossim_user"],
            self.__myconf["ossim_pass"])
            self.__myDB_connected = True
        #read host list
        query = 'select hostname,ip,fqdns from host where ip in  (select host_ip from  host_sensor_reference where sensor_name="%s");' % agent_name
        tmp = self.__myDB.exec_query(query)
        new_command = 'action="refresh_asset_list" list={'
        sendCommand = False
        for host in tmp:
            host_cmd = "%s=%s," % (host['ip'],host['hostname'])
            if host['fqdns'] is not None and host['fqdns'] != '':
                fqdns_list = host['fqdns'].split(',')
                for name in fqdns_list:
                    host_cmd += "%s," % name
            host_cmd = host_cmd[:-1]
            host_cmd+=';'
            sendCommand = True
            new_command += host_cmd
        new_command[:-1]
        new_command += '}'
        # add this connection to the transaction map
        #transaction = self.__transaction_id_get()
        #self.transaction_map[transaction] = {'socket':requestor, 'time':time.time()}
        # append the transaction to the message for tracking
        if sendCommand:
            if self.control_agents.has_key(agent_id):
                try:
                    self.control_agents[agent_id].wfile.write(new_command + ' transaction="NA"\n')
                    logger.info("Updating asset list to agent: %s " % (agent_id))
                    logger.debug("Cmd: %s" % new_command)
                except socket.error,e:
                    logger.warning("it can't send messages to :%s" % agent_id)
            else:
                logger.warning("No agent :%s" % agent_id)
        else:
开发者ID:DuVale,项目名称:phpzdl,代码行数:58,代码来源:DoControl.py

示例8: get_services_by_hosts

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
 def get_services_by_hosts(self, hostip):
     query = 'select inet_ntoa(hss.ip) as ip, h.hostname as hostname, hss.port as port, hss.protocol as protocol,hss.service as service,hss.service_type as service_type from host h, host_services hss where hss.ip=inet_aton("%s") and (hss.protocol =1 or hss.protocol=0 or hss.protocol=6 or hss.protocol=17) and nagios=1 and inet_ntoa(hss.ip) = h.ip;' % hostip
     db = OssimDB()
     db.connect (self._tmp_conf["ossim_host"],
             self._tmp_conf["ossim_base"],
             self._tmp_conf["ossim_user"],
             self._tmp_conf["ossim_pass"])
     data = db.exec_query(query)
     db.close()
     return data
开发者ID:DuVale,项目名称:phpzdl,代码行数:12,代码来源:DoNagios.py

示例9: get_hostlist_from_hg

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
 def get_hostlist_from_hg(self,hgname):
     query="select host_ip from host_group_reference where host_group_name = '%s'" % hgname
     db = OssimDB()
     db.connect (self._tmp_conf["ossim_host"],
             self._tmp_conf["ossim_base"],
             self._tmp_conf["ossim_user"],
             self._tmp_conf["ossim_pass"])
     data = db.exec_query(query)
     db.close()
     return data
开发者ID:DuVale,项目名称:phpzdl,代码行数:12,代码来源:DoNagios.py

示例10: checkEncryptionKey

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
 def checkEncryptionKey(self,dbhost,dbbase,dbuser,dbpasswd):
     # 1 -check if file exist or if the key is in the database.
     mydb = OssimDB()
     mydb.connect(dbhost,
                       dbbase,
                       dbuser,
                       dbpasswd)
     select_query = " select value from config where conf=\"encryption_key\";" 
     insert_query =  "INSERT INTO config VALUES ('encryption_key', '%s')"
     data = mydb.exec_query(select_query)
           
     if not os.path.isfile(Const.ENCRYPTION_KEY_FILE) or data is None or data =="" or len(data)==0:            
         logger.info("Encryption key file doesn't exist... making it at .. %s and save it to db" % Const.ENCRYPTION_KEY_FILE)
         p = sub.Popen('dmidecode', stdout=sub.PIPE, stderr=sub.PIPE)
         output, errors = p.communicate()
         reg_str = "UUID:\s+(?P<uuid>[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12})"
         pt = re.compile(reg_str, re.M)
         match_data = pt.search(output)
         key = ""
         extra_data = ""
         d =datetime.today()
         if match_data is not None:
             key = match_data.group('uuid')
             extra_data = "#Generated using dmidecode on %s\n" % d.isoformat(' ')                
         else:
             logger.error("I can't obtain system uuid. Generating a random uuid. Please do backup your encrytion key file: %s" % Const.ENCRYPTION_KEY_FILE)
             extra_data = "#Generated using random uuid on %s\n" % d.isoformat(' ')
             key = uuid.uuid4()
         newfile = open(Const.ENCRYPTION_KEY_FILE,'w')
         mydb.exec_query(insert_query % key)
         key = "key=%s\n" % key
         newfile.write("#This file is generated automatically by ossim. Please don't modify it!\n")            
         newfile.write(extra_data)
         newfile.write("[key-value]\n")
         newfile.write(key)
         newfile.close()            
         #insert the key in db..
         pw = pwd.getpwnam('www-data')
         os.chown(Const.ENCRYPTION_KEY_FILE, pw.pw_uid, pw.pw_gid)
         os.chmod(Const.ENCRYPTION_KEY_FILE, stat.S_IRUSR)
         # chown www-data.www-data /etc/ossim/framework/db_encryption_key
         # chmod 400 /etc/ossim/framework/db_encryption_key
     mydb.close()
开发者ID:DuVale,项目名称:phpzdl,代码行数:45,代码来源:Framework.py

示例11: get_host_groups

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
 def get_host_groups(self):
     query = 'select name from host_group'
     db = OssimDB()
     db.connect (self._tmp_conf["ossim_host"],
             self._tmp_conf["ossim_base"],
             self._tmp_conf["ossim_user"],
             self._tmp_conf["ossim_pass"])
     data = db.exec_query(query)
     db.close()
     return data
开发者ID:DuVale,项目名称:phpzdl,代码行数:12,代码来源:DoNagios.py

示例12: _get_db_conf

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
    def _get_db_conf(self):

        # Now, complete config info from Ossim database
        #
        from OssimDB import OssimDB
        db = OssimDB(config_file=self.__configfile)
        db.connect(self["ossim_host"],
                   self["ossim_base"],
                   self["ossim_user"],
                   self["ossim_pass"])
        query = ''
        useEncryption = False
        if self["encryptionKey"]:
            query = "SELECT * FROM config where conf not like '%%_pass%%'"
            useEncryption = True
        else:
            query = "SELECT * FROM config"
            
        hash = db.exec_query(query)
        for row in hash:
            # values declared at config file override the database ones
            if row["conf"] not in self._conf:
                self[row["conf"]] = row["value"]
                
        #Now read pass
        if useEncryption: 

            hash = db.exec_query("SELECT *, AES_DECRYPT(value,'%s') as dvalue FROM config where conf like '%%_pass%%'" % self["encryptionKey"])
            
            for row in hash:
                # values declared at config file override the database ones
                if row["conf"] not in self._conf:
                    if row["dvalue"] is not None:
                        self[row["conf"]] = row["dvalue"]
                    else:
                        hash = db.exec_query("SELECT * FROM config where conf like '%s'" % row["conf"])
                        self[row["conf"]] = hash[0]["value"]
            
        db.close()
开发者ID:DuVale,项目名称:phpzdl,代码行数:41,代码来源:OssimConf.py

示例13: get_shedule_scan_type

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
 def get_shedule_scan_type(self, id):
     tmp_conf = OssimConf (Const.CONFIG_FILE)
     tmp_conn = None
     tmp_conn = OssimDB()
     tmp_conn.connect ( tmp_conf["ossim_host"],
                           tmp_conf["ossim_base"],
                           tmp_conf["ossim_user"],
                           tmp_conf["ossim_pass"])
     query = "SELECT type_scan FROM plugin_scheduler WHERE id = '%s'" % id
     hash = tmp_conn.exec_query(query)
     if hash != []:
         scan_type = hash[0]["type_scan"]
     else: 
         scan_type = None
     tmp_conn.close()
     return scan_type
开发者ID:cterron,项目名称:OSSIM,代码行数:18,代码来源:DoNessus.py

示例14: __get_latest_scan_dates

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
    def __get_latest_scan_dates(self):
        scan_date_array = {}
        tmp_conf = OssimConf (Const.CONFIG_FILE)
        tmp_conn = None
        self.__debug("Getting latest scan dates")
        tmp_conn = OssimDB()
        tmp_conn.connect ( tmp_conf["ossim_host"],
                              tmp_conf["ossim_base"],
                              tmp_conf["ossim_user"],
                              tmp_conf["ossim_pass"])

        query = "SELECT hostvul.ip as ip, date_format(hostvul.scan_date,\"%Y%m%d%H%i%s\") as scan_date FROM (SELECT ip, max(scan_date) AS mymax FROM host_vulnerability group by ip) AS myvul, host_vulnerability AS hostvul WHERE hostvul.ip=myvul.ip AND hostvul.scan_date=myvul.mymax"
        hash = tmp_conn.exec_query(query)

        for row in hash:
            scan_date_array[row["ip"]] = row["scan_date"]
        return scan_date_array
开发者ID:cterron,项目名称:OSSIM,代码行数:19,代码来源:DoNessus.py

示例15: load_active_hosts

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import exec_query [as 别名]
 def load_active_hosts(self):
     '''
     Loads those host that has nagios active and almost one service active
     '''
     query = "select h.ip, h.hostname from host h, host_scan hs,host_services hss where inet_aton(h.ip) = hss.ip and inet_aton(h.ip)=hs.host_ip and hss.nagios=1 and (hss.protocol =1 or hss.protocol=0 or hss.protocol=6 or hss.protocol=17) and hs.plugin_id=2007 group by ip;"
     db = OssimDB()
     db.connect (self._tmp_conf["ossim_host"],
             self._tmp_conf["ossim_base"],
             self._tmp_conf["ossim_user"],
             self._tmp_conf["ossim_pass"])
     data = db.exec_query(query)
     self._active_hosts.clear()
     for host in data:
         hostip = host['ip']
         hostname = host['hostname']
         self._active_hosts[hostip] = hostname
     db.close()
开发者ID:DuVale,项目名称:phpzdl,代码行数:19,代码来源:DoNagios.py


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