Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.6 kB
2
Indexable
Never
class RDSHostLogCollection(__BaseLogCollection):
    # Define constants for paths and filenames
    PAS_RPM_VERSION_LOG_PATH = "/rdsdbdata/tmp/pas_rpm_version/pas_rpm_version.log"
    PAS_RPM_VERSION_LOG_DIR = "/rdsdbdata/tmp/pas_rpm_version/"
    
    def __init__(self, domain, region, **kwargs):
        super().__init__(**kwargs)
        self.__ssm_client = get_ssm_client(region=region, rds_domain=domain)

    def collect_rpm_version_configs(self, instance_id, workflow_path):
        credentials = self.get_pas_credentials(PAS_ADMIN_OPS_ROLE)
        cmds = self.get_rds_s3_file_transfer_template(
            credentials["AccessKeyId"], credentials["SecretAccessKey"]
        )
        
        # Use variables instead of hardcoding paths and filenames
        cmds.append(f"export logfile={self.PAS_RPM_VERSION_LOG_PATH}")
        cmds.append(f"sudo mkdir -p {self.PAS_RPM_VERSION_LOG_DIR} || true")
        cmds.append(f"sudo chmod -R 777 {self.PAS_RPM_VERSION_LOG_DIR}")
        
        # Rest of the code using variables
        cmds.append(
            "sudo env -i /usr/bin/yum list installed | "
            "grep -i 'rds\|aws\|gdb\|glib\|kernel\|csd\|ams\|apg\|mysql\|psql\|postgres\|oscar' | "
            f"sudo sed 's/^/pas_rpm_version: /' > {self.PAS_RPM_VERSION_LOG_PATH}"
        )
        cmds.append("echo END >> {self.PAS_RPM_VERSION_LOG_PATH}")

        cmds.append(
            f"aws s3 cp ${{logfile}} "
            + f"{get_pas_logs_s3_dir_for_instance(workflow_path, instance_id[0].strip())} "
            + ">> $logfile 2>&1"
        )

        self.__ssm_client.run_cmd(instance_id[1], cmds)
Leave a Comment