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


Python OssimDB.close方法代码示例

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


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

示例1: NtopDiscovery

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

示例2: get_nets

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

示例3: __init__

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

示例4: get_sheduler_list_by_id

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

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

示例6: get_host_groups

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

示例7: get_services_by_hosts

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

示例8: get_shedule_scan_type

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

示例9: make_nagios_changes

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

示例10: load_active_hosts

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

示例11: _get_db_conf

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

示例12: checkEncryptionKey

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

示例13: OptimizeDB

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

    def __init__ (self) :
        self.__conf = None
        self.__conn = None
        self.__sleep = 86400
        self.__rand = 60
        threading.Thread.__init__(self)

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

        # database connection
        self.__conn = OssimDB()

        self.__rand = random.randrange(60, 300)

    def __cleanup (self) :
        self.__conn.close()

    def optimize (self, host, base, user, password):
        self.__conn.connect (host , base, user, password)

        print __name__, "Optimizing tables for database: %s" % base;
        query = "SHOW TABLES;";
        try:
            hash = self.__conn.exec_query(query)
        except Exception, e:
            print __name__, \
                ': Error executing query (%s) """%s"""' % (query, e)
            return []

        hash = self.__conn.exec_query(query)

        for row in hash:
            print __name__, \
                "Optimizing %s.%s" % (base, row["tables_in_" + base])
            query = "OPTIMIZE TABLE `%s`;" % row["tables_in_" + base]
            hash = self.__conn.exec_query(query)
开发者ID:cterron,项目名称:OSSIM,代码行数:42,代码来源:OptimizeDB.py

示例14: _get_db_conf

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

示例15: get_sensors_by_id

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import close [as 别名]
    def get_sensors_by_id (self, id) :
        tmp_conf = OssimConf (Const.CONFIG_FILE)
        tmp_conn = None
        self.__debug("Getting sensors from policy id %d" % int(id))
        sensors = []
        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_sensor_reference where plugin_scheduler_id = %d" % int(id)
        hash = tmp_conn.exec_query(query)

        for row in hash:
            sensors.append(row["sensor_name"])

        print sensors

        if len(sensors) == 0:
            return False

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


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