class MonitorDatabase(Monitor):

    def open(self):

        location = self.plugin.get("config", "location")
        (db_type, host, db_name, user, password) = location.split(':')

        self.conn = DatabaseConn()
        self.conn.connect(db_type, host, db_name, user, password)


    def get_data(self, rule_name):
        """Get data from monitor."""
        
        if self.conn is None:
            return None

        data = ''
        query = self.queries[rule_name]

        logger.debug("Sending query to monitor: %s" % (query))
        result = self.conn.exec_query(query)
        logger.debug("Received data from monitor: %s" % (str(result)))
        return result


    def close(self):
        """Close monitor connection."""
        self.conn.close()
示例#2
0
    def open(self):

        location = self.plugin.get("config", "location")
        (db_type, host, db_name, user, password) = location.split(':')

        self.conn = DatabaseConn()
        self.conn.connect(db_type, host, db_name, user, password)
示例#3
0
class MonitorDatabase(Monitor):
    def open(self):

        location = self.plugin.get("config", "location")
        (db_type, host, db_name, user, password) = location.split(':')

        self.conn = DatabaseConn()
        self.conn.connect(db_type, host, db_name, user, password)

    def get_data(self, rule_name):
        """Get data from monitor."""

        if self.conn is None:
            return None

        data = ''
        query = self.queries[rule_name]

        logger.debug("Sending query to monitor: %s" % (query))
        result = self.conn.exec_query(query)
        logger.debug("Received data from monitor: %s" % (str(result)))
        return result

    def close(self):
        """Close monitor connection."""
        self.conn.close()
示例#4
0
 def __init__(self, conf):
     self.conf = conf
     type = self.conf.get('output-db', 'type')
     host = self.conf.get('output-db', 'host')
     base = self.conf.get('output-db', 'base')
     user = self.conf.get('output-db', 'user')
     password = self.conf.get('output-db', 'pass')
     self.conn = DatabaseConn()
     self.conn.connect(type, host, base, user, password)
     self.activated = True
    def open(self):

        location = self.plugin.get("config", "location")
        (db_type, host, db_name, user, password) = location.split(':')

        self.conn = DatabaseConn()
        self.conn.connect(db_type, host, db_name, user, password)
示例#6
0
class OutputDB():
    def __init__(self, conf):
        self.conf = conf
        type = self.conf.get('output-db', 'type')
        host = self.conf.get('output-db', 'host')
        base = self.conf.get('output-db', 'base')
        user = self.conf.get('output-db', 'user')
        password = self.conf.get('output-db', 'pass')
        self.conn = DatabaseConn()
        self.conn.connect(type, host, base, user, password)
        self.activated = True

    def event(self, e, priority=0):
        if self.conn is not None and self.activated:
            query = e.to_sql()
            print(query)
            try:
                self.conn.exec_query(query)
            except Exception as e:
                print(': Error executing query (%s)' % e)

        return

    def shutdown(self):
        print('Closing database connection..')
        self.conn.close()
        self.activated = False