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


Python OssimDB.connect方法代码示例

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


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

示例1: get_nets

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [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

示例2: _get_db_conf

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [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_sheduler_list_by_id

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [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

示例4: __init__

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [as 别名]
class Vulnerabilities :

    def __init__ (self) :
        self.__set_debug = True
        self.__conf = OssimConf(Const.CONFIG_FILE)
        self.__conn = OssimDB()
        self.__conn.connect( self.__conf['ossim_host'],
                             self.__conf['ossim_base'],
                             self.__conf['ossim_user'],
                             self.__conf['ossim_pass'])
        self.__id_pending = 65001 
        self.__id_false_positive = 65002
        self.__default_incident_type = 'Nessus Vulnerability'
        self.__nsr_fd = None
        self.__scanner_type = None
        self.__scan_time = None
        self.__ticket_default_user = "admin"
        self.__ticket_default_closed_description = "Automatic closed of the incident"
        self.__ticket_default_open_description = "Automatic open of the incident"

    def process(self, nsr_file, scan_date, scan_networks, scan_hosts) :
        self.__debug("Generating Incidents for found vulnerabilities")
        self.__scan_time = strftime('%Y-%m-%d %H:%M:%S')
        self.__scanner_type = self.__scanner_type or \
                            self.__conf["scanner_type"] or \
                            "openvas2"
        try:
            self.__nsr_fd = open(nsr_file)
        except Exception, e:
            self.__debug("Unable to open file %s: %s" % (nsr_file,e))
            return
        self.__parse_vulns_file()
        self.__debug("Automatic close of vulnerabilities")
        self.__traverse_vulns_incidents(scan_date, scan_networks, scan_hosts)
        self.__debug("Generating Incidents finished ok")
开发者ID:cterron,项目名称:OSSIM,代码行数:37,代码来源:Vulnerabilities.py

示例5: __init__

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [as 别名]
class SSHInventory:
    _interval = 3600

    def __init__(self):
        self._tmp_conf = OssimConf(Const.CONFIG_FILE)
        self.inv = Inventory()
        # Implement cache with timeout?????
        self.cache = []
        # threading.Thread.__init__(self)

    def connectDB(self):
        self.db = OssimDB()
        self.db.connect(
            self._tmp_conf["ossim_host"],
            self._tmp_conf["ossim_base"],
            self._tmp_conf["ossim_user"],
            self._tmp_conf["ossim_pass"],
        )

    def closeDB(self):
        self.db.close()

    def run(self):
        while True:
            self.process()
            time.sleep(self._interval)

    def process(self):
        # Check host with local credentials
        hosts = self.inv.getHostWithCredentials("SSH")
开发者ID:jhbsz,项目名称:ossimTest,代码行数:32,代码来源:SSHInventory.py

示例6: NtopDiscovery

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [as 别名]
class NtopDiscovery(threading.Thread):
    _interval = 100
    
    def __init__(self):
        self._tmp_conf = OssimConf (Const.CONFIG_FILE)
        #Implement cache with timeout?????
        self.inv = Inventory()
        self.cache = []
        threading.Thread.__init__(self)

    def connectDB(self):
        self.db = OssimDB()
        self.db.connect (self._tmp_conf["ossim_host"],
                         self._tmp_conf["ossim_base"],
                          self._tmp_conf["ossim_user"],
                         self._tmp_conf["ossim_pass"])
    
    def closeDB(self):
        self.db.close()
        
    def getDataFromSensor(self, ip, port):
        logger.debug("Retrieving NTOP data from %s" % ip)
        try:
            f = urllib.urlopen("http://%s:%s/python/get.py" % (ip, port))
            return f.read()
        except IOError, msg:
            #print msg
            logger.error("Error retrieving NTOP information from %s - msg:%s" % (ip, msg))
            return None
开发者ID:DuVale,项目名称:phpzdl,代码行数:31,代码来源:NtopDiscovery.py

示例7: ControlPanel

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [as 别名]
class ControlPanel (threading.Thread) :

    def __init__ (self) :
        self.__conf = None      # ossim configuration values (ossim.conf)
        self.__conn = None      # cursor to ossim database
        self.__rrd_path = {}    # path for global, net, host and level rrds
        threading.Thread.__init__(self)


    def __startup (self) :

        # configuration values
        self.__conf = OssimConf (Const.CONFIG_FILE)

        # database connection
        self.__conn = OssimDB()
        self.__conn.connect ( self.__conf["ossim_host"],
                              self.__conf["ossim_base"],
                              self.__conf["ossim_user"],
                              self.__conf["ossim_pass"])

        # rrd paths
        if self.__conf["rrdtool_path"]:
            Const.RRD_BIN = os.path.join(self.__conf["rrdtool_path"], "rrdtool")

        try:
            for dest in [ "global", "net", "host", "level" ] :
                self.__rrd_path[dest] = \
                    os.path.join(self.__conf["mrtg_rrd_files_path"], 
                        '%s_qualification' % (dest))
        except OSError, e:
            print >>sys.stderr, "Error reading RRD path: " + e
            sys.exit()
开发者ID:cterron,项目名称:OSSIM,代码行数:35,代码来源:ControlPanel.py

示例8: __init__

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [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

示例9: __init__

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [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

示例10: get_hostlist_from_hg

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [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

示例11: get_host_groups

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [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_services_by_hosts

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [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

示例13: get_shedule_scan_type

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [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: load_active_hosts

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [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

示例15: __get_latest_scan_dates

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import connect [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


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