Example #1
0
#    subject to the above copyright notice and this permission notice shall being included
#    in all copies or substantial portions of the Software.

# -- config --
# description: Retrieve a list of roles.
# http_method: get
# lock: False
# tags: Postgres, Psql
# -- end config --

from os import linesep
from extension import CmdRun, ToolKit, Constants

# Spawn Instances
run = CmdRun()  # <class> Run
toolkit = ToolKit()  # <class> Misc. functions

# ******************
# *  SQL SENTENCE  *
# ******************
sql = ("\du")
sql_code = toolkit.write_temp(sql)

# ****************
# *  SQL RUNNER  *
# ****************
output = run.sql(sql_code)
print(output)
print("{status}=ok".format(status=Constants.API_SUMMARY_STRING))

toolkit.exit(0)
# description: Deletes a role
# param: role - Your ROLE name
# http_method: post
# lock: False
# tags: Postgres, Psql
# -- end config --

from os import linesep
from extension import Sanitize, CmdRun
from extension import ToolKit, Constants
from extension import ParamHandle as Param

# Spawn Instances
p = Param()  # <class> Parameter manipulation
real_escape_string = Sanitize()  # <class> Escape Routines
toolkit = ToolKit()  # <class> Misc. functions
params = p.list()  # <dict>   Input params list
run = CmdRun()  # <class> Runs the query

# ************************************
# *  DEFINE PARAMETERS AND VALIDATE  *
# ************************************
sanitized_arguement = {}  # The actual API params we pass to psql

param = "role"
role = Param()
role.value = params[param]
role.name = param
role.max_length = Constants.POSTGRES_NAMEDATA_LEN
role.require = True
role.sanitizier = "sql"
#    subject to the above copyright notice and this permission notice shall being included
#    in all copies or substantial portions of the Software.

# -- config --
# description: Identify slow queries
# http_method: get
# lock: False
# tags: Postgres, Psql
# -- end config --

from os import linesep
from extension import CmdRun, ToolKit, Constants

# Spawn Instances
run = CmdRun()        # <class> Run
toolkit = ToolKit()  # <class> Misc. functions


# ******************
# *  SQL SENTENCE  *
# ******************
sql = ("SELECT"
       "    pid,"
       "    current_timestamp - xact_start as xact_runtime,"
       "    query"
       " FROM pg_stat_activity WHERE query NOT LIKE '%pg_stat_activity%' "
       " ORDER BY xact_start;"
       )
sql_code = toolkit.write_temp(sql)

# filtered_params: password
# http_method: post
# lock: False
# tags: Postgres, CREATEROLE, Psql
# -- end config --

from os import linesep
from extension import Sanitize, CmdRun
from extension import ToolKit, Constants
from extension import ParamHandle as Param
import psycopg2

# Spawn Instances
p = Param()  # <class> Parameter manipulation
real_escape_string = Sanitize()  # <class> Escape Routines
toolkit = ToolKit()  # <class> Misc. functions
params = p.list()  # <dict>   Input params list
run = CmdRun()  # <class> Runs the query

try:
    conn = psycopg2.connect("dbname='postgres' user='******' host='localhost'")
except:
    print "I am unable to connect to the database"

cursor = conn.cursor()

# ************************************
# *  DEFINE PARAMETERS AND VALIDATE  *
# ************************************
sanitized_arguement = {}  # The actual API params we pass to psql
# param: pid -  If supplied, will terminate all connections to this pid.
# param: client_address -  If supplied, will terminate all connections to this IP.
# http_method: post
# lock: False
# tags: Postgres, Psql
# -- end config --

from os import linesep
from extension import Sanitize, CmdRun
from extension import ToolKit, Constants
from extension import ParamHandle as Param

# Spawn Instances
p = Param()  # <class> Parameter manipulation
real_escape_string = Sanitize()  # <class> Escape Routines
toolkit = ToolKit()  # <class> Misc. functions
params = p.list()  # <dict>   Input params list
run = CmdRun()  # <class> Runs the query

# ************************************
# *  DEFINE PARAMETERS AND VALIDATE  *
# ************************************
sanitized_arguement = {}  # The actual API params we pass to psql

param = "database"
database = Param()
database.value = params[param]
database.name = param
database.max_length = Constants.POSTGRES_NAMEDATA_LEN
database.sanitizier = "sql"
database.set_value_if_defined()
Example #6
0
#    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
#    the Software, and to permit persons to whom the Software is furnished to do so,
#    subject to the above copyright notice and this permission notice shall being included
#    in all copies or substantial portions of the Software.

# -- config --
# description: Retrieve pg stats connection activity (whos connected)
# http_method: get
# lock: False
# tags: Postgres, PGaaS, cit-ops
# -- end config --

from extension import ToolKit, CmdRun, Constants

# Spawn Instances
toolkit = ToolKit()
run = CmdRun()  # <class> Run

# ******************
# *  SQL SENTENCE  *
# ******************
sql = ("BEGIN; select * from pg_stat_activity; COMMIT;")
sql_code = toolkit.write_temp(sql)

# ****************
# *  SQL RUNNER  *
# ****************
output = run.sql(sql_code)

# **********************
# *  OUTPUT PROCESSOR  *