Ejemplo n.º 1
0
    def configure_raid(self, device_id):
        _g_logger.info("Configuring RAID on " + str(device_id))
        if self.args.formatVolume:
            exe = self.conf.get_script_location("configureRaid")
        else:
            exe = self.conf.get_script_location("assembleRaid")

        if self.args.raidLevel.upper() == "NONE":
            raise plugin_exceptions.AgentPluginParameterBadValueException(
                "mount_volume", "raidLevel",
                "When using multiple volumes you must specify a RAID level")

        try:
            raid_level = str(int(self.args.raidLevel[4:]))
        except:
            raise plugin_exceptions.AgentPluginParameterBadValueException(
                "mount_volume", "raidLevel", "Invalid RAID level")

        cmd = [exe, raid_level, device_id]

        for d in self.args.devices:
            cmd.append(d)

        _g_logger.debug("Running the raid configuration command %s" % str(cmd))
        (stdout, stderr, rc) = plugin_utils.run_command(self.conf, cmd)
        _g_logger.debug("configure raid results: %d stdout=%s stderr=%s" %
                        (rc, str(stdout), str(stderr)))

        if rc != 0:
            _g_logger.error(
                "Failed to run raid configuration: stdout=%s\nstderr=%s" %
                (str(stdout), str(stderr)))
            raise exceptions.AgentExecutableException(cmd, rc, stdout, stderr)
Ejemplo n.º 2
0
 def run(self):
     command = [self.conf.get_script_location("removeUser"),
                self.args.userId]
     (stdout, stderr, rc) = plugin_utils.run_command(self.conf, command, with_sudo=True)
     if rc != 0:
         raise exceptions.AgentExecutableException(
                 command, rc, stdout, stderr)
     return plugin_base.PluginReply(rc, message="job removeUser succeeded.")
Ejemplo n.º 3
0
def _unmount(conf, mount_point):
    command = [conf.get_script_location("unmount"), mount_point]
    (stdout, stderr, rc) = plugin_utils.run_command(conf, command)
    if rc != 0:
        _g_logger.info("The unmount of %s did not succeed: %s" %
                       (mount_point, stderr))
        raise exceptions.AgentExecutableException(command, rc, stdout, stderr)
    return rc
Ejemplo n.º 4
0
def get_dhcp_ip_address(conf):
    (stdout, stderr, rc) = utils.run_script(conf, "getDhcpAddress", [])
    if rc != 0:
        raise exceptions.AgentExecutableException(
            "getDhcpAddress", rc, stdout, stderr)

    dhcp_address = stdout.strip()
    return dhcp_address
Ejemplo n.º 5
0
def open_encrypted_device(conf, raw_device_id, encrypted_device_id, key_file):
    command = [
        conf.get_script_location("openEncryption"), raw_device_id,
        encrypted_device_id, key_file
    ]
    (stdout, stderr, rc) = run_command(conf, command)
    if rc != 0:
        raise exceptions.AgentExecutableException(command, rc, stdout, stderr)
    return rc
Ejemplo n.º 6
0
def agent_format(conf, device_id, file_system, mount_point, encryption_key):
    enc_str = str(encryption_key is not None).lower()
    command = [
        conf.get_script_location("format"), device_id, file_system,
        mount_point, enc_str
    ]
    (stdout, stderr, rc) = run_command(conf, command)
    if rc != 0:
        raise exceptions.AgentExecutableException(command, rc, stdout, stderr)
    return rc
Ejemplo n.º 7
0
 def setup_encryption(self, device_id, encrypted_device_id, key_file_path):
     command = [
         self.conf.get_script_location("setupEncryption"), device_id,
         encrypted_device_id, key_file_path
     ]
     (stdout, stderr, rc) = plugin_utils.run_command(self.conf, command)
     if rc != 0:
         raise exceptions.AgentExecutableException(command, rc, stdout,
                                                   stderr)
     return rc
Ejemplo n.º 8
0
def _close_encrypted_device(conf, encrypted_device_id):
    command = [
        conf.get_script_location("closeEncryption"), encrypted_device_id
    ]
    (stdout, stderr, rc) = plugin_utils.run_command(conf, command)
    if rc != 0:
        _g_logger.info("The close of encrypted %s did not succeed: %s" %
                       (encrypted_device_id, stderr))
        raise exceptions.AgentExecutableException(command, rc, stdout, stderr)
    return rc
Ejemplo n.º 9
0
def mount(conf, device_id, file_system, mount_point):
    if device_id.startswith("es"):
        device_id = "mapper/" + device_id

    command = [
        conf.get_script_location("mount"), device_id, file_system, mount_point
    ]
    (stdout, stderr, rc) = run_command(conf, command)
    if rc != 0:
        raise exceptions.AgentExecutableException(command, rc, stdout, stderr)
    return rc
Ejemplo n.º 10
0
def get_device_mappings(conf):
    command = [conf.get_script_location("listDevices")]

    (stdout, stderr, rc) = run_command(conf, command)
    if rc != 0:
        raise exceptions.AgentExecutableException(command, rc, stdout, stderr)

    try:
        device_mapping_list = []
        lines = stdout.split(os.linesep)
        for line in lines:
            parts = line.split()
            if len(parts) != 5:
                continue

            elements = parts[0].split("/")
            device_id = elements[len(elements) - 1]
            file_system = parts[1]
            mount_point = parts[2]
            try:
                size = int(parts[3])
                used = int(parts[4])
            except ValueError:
                continue
            if parts[0].startswith("/dev/mapper"):
                encrypted = True
            else:
                encrypted = False

            if mount_point == "/":
                device_type = DeviceTypes.ROOT
            elif mount_point == conf.storage_mountpoint:
                device_type = DeviceTypes.EPHEMERAL
            else:
                device_type = DeviceTypes.CUSTOM

            device_mapping = {
                "device_id": device_id,
                "encrypted": encrypted,
                "file_system": file_system,
                "mount_point": mount_point,
                "size": size,
                "used": used,
                "device_type": device_type
            }
            device_mapping_list.append(device_mapping)
    except Exception as ex:
        _g_logger.exception(str(ex))
        _g_logger.error("listDevice stdout: " + stdout)
        _g_logger.error("listDevice stderr: " + stderr)
        raise

    return device_mapping_list
Ejemplo n.º 11
0
def install_ossec(conf):
    command = conf.get_script_location("installOssec")
    (stdout, stderr, rc) = run_command(conf, command)
    if rc != 0:
        raise exceptions.AgentExecutableException(command, rc, stdout, stderr)
    return rc