Beispiel #1
0
def insert_agent_host():
    """Insert first agent and host in the database.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    idx_agent = 1
    idx_host = 1
    agent_name = '_infoset'
    config = jm_configuration.ConfigAgent(agent_name)

    # Add agent
    if db_agent.idx_exists(idx_agent) is False:
        # Generate a UID and add a record in the database
        uid = agent.get_uid(config)

    # Add host
    if db_host.idx_exists(idx_host) is False:
        record = Host(
            description=jm_general.encode('Infoset Server'),
            hostname=jm_general.encode(socket.getfqdn()))
        database = db.Database()
        database.add(record, 1106)

    # Add to Agent / Host table
    if db_hostagent.host_agent_exists(idx_host, idx_agent) is False:
        record = HostAgent(idx_host=idx_host, idx_agent=idx_agent)
        database = db.Database()
        database.add(record, 1107)
Beispiel #2
0
    def upload(self):
        """Post system data to the central server.

        Args:
            None

        Returns:
            None

        """
        # Get hostname
        hostname = socket.getfqdn()

        # Get the UID for the agent
        uid = Agent.get_uid(hostname)

        # Initialize key variables
        agent = Agent.Agent(uid, self.config, hostname)

        # Update agent with system data
        _update_agent_system(agent)

        # Update agent with disk data
        _update_agent_disk(agent)

        # Update agent with network data
        _update_agent_net(agent)

        # Post data
        success = agent.post()

        # Purge cache if success is True
        if success is True:
            agent.purge()
Beispiel #3
0
def insert_agent_host():
    """Insert first agent and host in the database.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    idx_agent = 1
    idx_host = 1
    agent_name = '_infoset'

    # Add agent
    if db_agent.idx_exists(idx_agent) is False:
        record = Agent(
            id=jm_general.encode('_SYSTEM_RESERVED_'),
            name=jm_general.encode(agent_name))
        database = db.Database()
        database.add(record, 1109)

        # Generate a UID
        uid = agent.get_uid(agent_name)
        database = db.Database()
        session = database.session()
        record = session.query(Agent).filter(Agent.idx == idx_agent).one()
        record.id = jm_general.encode(uid)
        database.commit(session, 1073)

    # Add host
    if db_host.idx_exists(idx_host) is False:
        record = Host(
            description=jm_general.encode('Infoset Server'),
            hostname=jm_general.encode(socket.getfqdn()))
        database = db.Database()
        database.add(record, 1106)

    # Add to Agent / Host table
    if db_hostagent.host_agent_exists(idx_host, idx_agent) is False:
        record = HostAgent(idx_host=idx_host, idx_agent=idx_agent)
        database = db.Database()
        database.add(record, 1107)
Beispiel #4
0
    def query(self):
        """Query all remote hosts for data.

        Args:
            None

        Returns:
            None

        """
        # Check each hostname
        hostnames = self.config.agent_snmp_hostnames()
        for hostname in hostnames:
            # Get valid SNMP credentials
            validate = snmp_manager.Validate(
                hostname, self.snmp_config.snmp_auth())
            snmp_params = validate.credentials()

            # Log message
            if snmp_params is None:
                log_message = (
                    'No valid SNMP configuration found '
                    'for host "%s" ') % (hostname)
                log.log2warn(1006, log_message)
                continue

            # Create Query make sure MIB is supported
            snmp_object = snmp_manager.Interact(snmp_params)
            snmp_query = mib_sentry3.init_query(snmp_object)
            if snmp_query.supported() is False:
                log_message = (
                    'The Sentry3 MIB is not supported by host  "%s"'
                    '') % (hostname)
                log.log2warn(1001, log_message)
                continue

            # Get the UID for the agent after all preliminary checks are OK
            uid_env = agent.get_uid(hostname)

            # Post data to the remote server
            self.upload(uid_env, hostname, snmp_query)