Exemplo n.º 1
0
#    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 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))
#    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: 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)
# 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"
sanitized_arguement[param] = role.get()
# 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 = "role"
role = Param()