Beispiel #1
0
    def disable_and_exit_if_extension_is_not_installed(self, ext, db=None):
        if not self.extension_installed(ext, db=db, silent=True):
            self.disable()
            raise PluginDisableException(
                """Disable plugin and exit, because '{0}' \
extension is not installed. Enable it in PostgreSQL instance: '{1}', \
if needed and restart.""".format(ext, Pooler.connection_string(db)))
Beispiel #2
0
    def disable_and_exit_if_archive_mode_is_not_on(self, db=None):
        param = Pooler.get_sys_param('archive_mode', db=db)
        if param != 'on':
            self.disable()
            raise PluginDisableException("""Disable plugin and exit, because '{0}' \
parameter is not 'ON'. Enable it "{1}" in PostgreSQL instance, \
if needed and restart.""".format('archive_mode', 'alter system set archive_mode = on;'))
Beispiel #3
0
    def disable_and_exit_if_not_pgpro_ee(self, db=None):
        if not Pooler.is_pgpro_ee(db):
            self.disable()
            raise PluginDisableException("""Disable plugin and exit, because \
PostgresPro Enterprise Edition is not detected [instance: '{0}']
""".format(Pooler.connection_string(db)))
Beispiel #4
0
    def run(self, zbx):
        config_pg_probackup_path = self.plugin_config('pg_probackup_path')

        if config_pg_probackup_path is None or config_pg_probackup_path == '':
            self.disable()
            raise PluginDisableException(
                """Disable plugin and exit, because the parameter 'pg_probackup_path' in section [pgprobackup] is not 
                set. Set this parameter if needed and restart.""")
        config_backup_dirs = self._plugin_config.get('backup_dirs', None)

        if config_backup_dirs is None or config_backup_dirs == '':
            self.disable()
            raise PluginDisableException(
                """Disable plugin and exit, because the parameter 'backup_dirs' in section [pgprobackup] is not set. 
                Set this parameter if needed and restart.""")

        backup_dirs = config_backup_dirs.split(',')
        dirs = []
        for _dir in backup_dirs:
            dirs.append({'{#BACKUPDIR}': _dir})

            dir_size = self.dir_size(_dir)
            if self.os_walk_error:
                self.log.error(
                    "Error in count size pg_probackup dir: {backup_catalog}. Error: {error}".format(
                        backup_catalog=_dir, error=str(self.os_walk_error)))
            else:
                zbx.send(self.key_dir_size.format('[' + _dir + ']'), dir_size)

            # Search for backups with bad status is done by running
            # "pg_probackup  show -B backup_dir" command
            command = [config_pg_probackup_path, 'show', '-B', _dir, '--format=json']
            process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            stdout, stderr = process.communicate()
            return_code = process.returncode
            if return_code != 0:
                self.log.error(
                    "The command: {command} return code {return_code}. Error: {error}".format(command=command,
                                                                                              return_code=return_code,
                                                                                              error=stderr))
                continue
            try:
                result = json.loads(stdout.decode('utf-8'))
            except Exception as e:
                self.log.error('Error in convert data: {stdout} \n {e}'.format(stdout=stdout, e=e))
                continue
            no_error= True
            for instance in result:
                for backup in instance.get('backups', []):
                    status = backup['status']
                    if status in ['ERROR', 'CORRUPT', 'ORPHAN']:
                        error = 'Backup with id: {backup_id} in instance: {instance_name} in pg_probackup dir: ' \
                                '{backup_catalog}  has status: {status}.'.format(backup_id=backup['id'],
                                                                                 instance_name=instance['instance'],
                                                                                 status=status, backup_catalog=_dir)
                        self.log.info(error)
                        no_error = False
                        zbx.send(self.key_dir_error.format('[' + _dir + ']'), error)
            if no_error:
                zbx.send(self.key_dir_error.format('[' + _dir + ']'), 'ok')

        zbx.send(self.key_main.format('[]'), zbx.json({'data': dirs}))
        del dirs