Ejemplo n.º 1
0
    def __init__(self, configuration, entity, entry_point_group):
        """
        Initialize the plugin.
        @type configuration: Configuration object
        @param configuration: the configuration
        @type entity: L{TNArchipelEntity}
        @param entity: the entity that owns the plugin
        @type entry_point_group: string
        @param entry_point_group: the group name of plugin entry_point
        """
        TNArchipelPlugin.__init__(self, configuration=configuration, entity=entity, entry_point_group=entry_point_group)
        db_file                 = self.configuration.get("HEALTH", "health_database_path")
        collection_interval     = self.configuration.getint("HEALTH", "health_collection_interval")
        max_rows_before_purge   = self.configuration.getint("HEALTH", "max_rows_before_purge")
        max_cached_rows         = self.configuration.getint("HEALTH", "max_cached_rows")
        log_file                = self.configuration.get("LOGGING", "logging_file_path")
        self.collector = TNThreadedHealthCollector(db_file,collection_interval, max_rows_before_purge, max_cached_rows)
        self.logfile = log_file

        # permissions
        self.entity.permission_center.create_permission("health_history", "Authorizes user to get the health history", False)
        self.entity.permission_center.create_permission("health_info", "Authorizes user to get entity information", False)
        self.entity.permission_center.create_permission("health_logs", "Authorizes user to get entity logs", False)
        registrar_items = [
                            {   "commands" : ["health"],
                                "parameters": [{"name": "limit", "description": "Max number of returned entries. Equals 1 if ommited"}],
                                "method": self.message_health_info,
                                "permissions": ["health_info"],
                                "description": "Get my last health information" },
                            {   "commands" : ["logs"],
                                "parameters": [{"name": "limit", "description": "Max number of returned entries. Equals 1 if ommited"}],
                                "method": self.message_get_logs,
                                "permissions": ["health_logs"],
                                "description": "Get my last logs information" }
                            ]
        self.entity.add_message_registrar_items(registrar_items)

        self.entity.register_hook("HOOK_ARCHIPELENTITY_XMPP_AUTHENTICATED", method=self.start_collector)