Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.9 kB
3
Indexable
Never
class RDSHostLogCollection(__BaseLogCollection):
    # Define constants for paths and filenames
    CSD_LOGFILE_PATH = "/rdsdbdata/tmp/csd_configs.log"
    GET_CSD_CONFIGS_SH_PATH = "/tmp/GetCsdConfigs.sh"

    def __init__(self, instance_id, workflow_path, **kwargs):
        super().__init__(**kwargs)
        self.instance_id = instance_id
        self.workflow_path = workflow_path
        self.__ssm_client = get_ssm_client(region=region, rds_domain=domain)

    def collect_csd_configs(self):
        """
        Gather current CSD configs
        """
        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.CSD_LOGFILE_PATH}")
        cmds.append("sudo date >> $logfile 2>&1")
        cmds.append(f'sudo echo "Copy GetCsdConfigs.sh to {self.GET_CSD_CONFIGS_SH_PATH}" >> $logfile 2>&1')
        cmds.append(
            f"aws s3 cp {self.base_s3_location}/aurora-db-logs/GetCsdConfigs.sh {self.GET_CSD_CONFIGS_SH_PATH} "
            + ">> $logfile 2>&1"
        )
        cmds.append('sudo echo "Run GetCsdConfigs.sh" >> $logfile 2>&1')
        cmds.append(f"sudo chmod +x {self.GET_CSD_CONFIGS_SH_PATH}  >> $logfile 2>&1")
        cmds.append(f"sudo bash {self.GET_CSD_CONFIGS_SH_PATH}  >> $logfile 2>&1")
        cmds.append('sudo echo "Copy {self.CSD_LOGFILE_PATH} to S3" >> $logfile 2>&1')
        cmds.append("sleep 2")
        cmds.append(
            f"aws s3 cp ${{logfile}} "
            + f"{get_pas_logs_s3_dir_for_instance(self.workflow_path, self.instance_id[0].strip())} "
            + ">> $logfile 2>&1"
        )

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