Exemple #1
0
def run(args):
    log = logger().getlogger

    pg = postgresql(args)
    pgb = pgbouncer(args)

    if args.sendtrap:
        info = {}
        log.info("sendtrap start")

        pgInfo = pg.info()
        info.update(pgInfo)

        pgbInfo = pgb.info()
        info.update(pgbInfo)
        log.info("sendtrap result: {}".format(info))

        zbx = sendproto(pg.config['zbx_server'], pg.config['zbx_port'])
        resp = zbx.send(info)

        log.info("send status: {}".format(resp))

    elif args.discover:
        info = {}
        log.info("discover start")

        pgInfo = pg.discover()
        pgbInfo = pgb.discover()

        info['data'] = pgInfo + pgbInfo

        log.info("discover result: {}".format(
            json.dumps(info, sort_keys=True, indent=4, separators=(',', ':'))))
        print(json.dumps(info, indent=4))
Exemple #2
0
    def pgbouncer_resume(self, dbname):
        """ resume given database """
        from options import TERSE
        if not TERSE:
            print "resume %s;" % dbname
        p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host,
                                self.pgbouncer_port)

        p.resume(dbname)
Exemple #3
0
    def pgbouncer_databases(self):
        """ return pgbouncer database list: name, database, host, port """
        p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host,
                                self.pgbouncer_port)

        for d in p.databases():
            yield d['name'], d['database'], d['host'], d['port']

        return
Exemple #4
0
    def pgbouncer_pause(self, dbname):
        """ pause given database """
        from options import VERBOSE
        if VERBOSE:
            print "pause %s;" % dbname
        p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host,
                                self.pgbouncer_port)

        p.pause(dbname)
Exemple #5
0
    def pgbouncer_resume(self, dbname):
        """ resume given database """
        from options import TERSE
        if not TERSE:
            print "resume %s;" % dbname
        p = pgbouncer.pgbouncer(self.pgbouncer_conf,
                                self.dbuser,
                                self.host,
                                self.pgbouncer_port)

        p.resume(dbname)
Exemple #6
0
    def switch(self):
        """ edit pgbouncer configuration file to have canonical dbname point
        to given date (backup_date) """

        p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host,
                                self.postgres_port)

        newconffile = p.switch_to_database(self.dbname, self.dated_dbname,
                                           self.postgres_port)

        self.pgbouncer_update_conf(newconffile)
Exemple #7
0
    def pgbouncer_pause(self, dbname):
        """ pause given database """
        from options import VERBOSE
        if VERBOSE:
            print "pause %s;" % dbname
        p = pgbouncer.pgbouncer(self.pgbouncer_conf,
                                self.dbuser,
                                self.host,
                                self.pgbouncer_port)

        p.pause(dbname)
Exemple #8
0
    def pgbouncer_databases(self):
        """ return pgbouncer database list: name, database, host, port """
        p = pgbouncer.pgbouncer(self.pgbouncer_conf,
                                self.dbuser,
                                self.host,
                                self.pgbouncer_port)

        for d in p.databases():
            yield d['name'], d['database'], d['host'], d['port']

        return
Exemple #9
0
    def pgbouncer_del_database(self, dbname):
        """ edit pgbouncer configuration file to add a database """
        from options import VERBOSE

        p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host,
                                self.postgres_port)

        newconffile = p.del_database(dbname)

        self.pgbouncer_update_conf(newconffile)

        if VERBOSE:
            print "deleted a pgbouncer database %s" % dbname
Exemple #10
0
    def switch(self):
        """ edit pgbouncer configuration file to have canonical dbname point
        to given date (backup_date) """

        p = pgbouncer.pgbouncer(self.pgbouncer_conf,
                                self.dbuser,
                                self.host,
                                self.postgres_port)

        newconffile = p.switch_to_database(self.dbname,
                                           self.dated_dbname,
                                           self.postgres_port)

        self.pgbouncer_update_conf(newconffile)
Exemple #11
0
    def pgbouncer_del_database(self, dbname):
        """ edit pgbouncer configuration file to add a database """
        from options import VERBOSE

        p = pgbouncer.pgbouncer(self.pgbouncer_conf,
                                self.dbuser,
                                self.host,
                                self.postgres_port)

        newconffile = p.del_database(dbname)

        self.pgbouncer_update_conf(newconffile)

        if VERBOSE:
            print "deleted a pgbouncer database %s" % dbname
Exemple #12
0
    def pgbouncer_add_database(self, dbname=None):
        """ edit pgbouncer configuration file to add a database """
        from options import TERSE

        p = pgbouncer.pgbouncer(self.pgbouncer_conf, self.dbuser, self.host,
                                self.postgres_port)

        if dbname is None:
            dbname = self.dated_dbname

        newconffile = p.add_database(dbname, self.postgres_port)

        self.pgbouncer_update_conf(newconffile)

        if not TERSE:
            print "added a pgbouncer database %s" % dbname
Exemple #13
0
    def pgbouncer_add_database(self, dbname = None):
        """ edit pgbouncer configuration file to add a database """
        from options import TERSE

        p = pgbouncer.pgbouncer(self.pgbouncer_conf,
                                self.dbuser,
                                self.host,
                                self.postgres_port)

        if dbname is None:
            dbname = self.dated_dbname

        newconffile = p.add_database(dbname, self.postgres_port)

        self.pgbouncer_update_conf(newconffile)

        if not TERSE:
            print "added a pgbouncer database %s" % dbname