Return data to a postgresql server
| maintainer: | None |
|---|---|
| maturity: | New |
| depends: | psycopg2 |
| platform: | all |
To enable this returner the minion will need the psycopg2 installed and the following values configured in the minion or master config:
returner.postgres.host: 'salt'
returner.postgres.user: 'salt'
returner.postgres.passwd: 'salt'
returner.postgres.db: 'salt'
returner.postgres.port: 5432
Alternative configuration values can be used by prefacing the configuration. Any values not found in the alternative configuration will be pulled from the default location:
alternative.returner.postgres.host: 'salt'
alternative.returner.postgres.user: 'salt'
alternative.returner.postgres.passwd: 'salt'
alternative.returner.postgres.db: 'salt'
alternative.returner.postgres.port: 5432
Running the following commands as the postgres user should create the database correctly:
psql << EOF
CREATE ROLE salt WITH PASSWORD 'salt';
CREATE DATABASE salt WITH OWNER salt;
EOF
psql -h localhost -U salt << EOF
--
-- Table structure for table 'jids'
--
DROP TABLE IF EXISTS jids;
CREATE TABLE jids (
jid varchar(20) PRIMARY KEY,
load text NOT NULL
);
--
-- Table structure for table 'salt_returns'
--
DROP TABLE IF EXISTS salt_returns;
CREATE TABLE salt_returns (
added TIMESTAMP WITH TIME ZONE DEFAULT now(),
fun text NOT NULL,
jid varchar(20) NOT NULL,
return text NOT NULL,
id text NOT NULL,
success boolean
);
CREATE INDEX ON salt_returns (added);
CREATE INDEX ON salt_returns (id);
CREATE INDEX ON salt_returns (jid);
CREATE INDEX ON salt_returns (fun);
EOF
Required python modules: psycopg2
To use the postgres returner, append '--return postgres' to the salt command.
salt '*' test.ping --return postgres
To use the alternative configuration, append '--return_config alternative' to the salt command.
2015.5.0 新版功能.
salt '*' test.ping --return postgres --return_config alternative
To override individual configuration items, append --return_kwargs '{"key:": "value"}' to the salt command.
2016.3.0 新版功能.
salt '*' test.ping --return postgres --return_kwargs '{"db": "another-salt"}'
salt.returners.postgres.get_fun(fun)¶Return a dict of the last function called for all minions
salt.returners.postgres.get_jid(jid)¶Return the information returned when the specified job id was executed
salt.returners.postgres.get_jids()¶Return a list of all job ids
salt.returners.postgres.get_load(jid)¶Return the load data that marks a specified jid
salt.returners.postgres.get_minions()¶Return a list of minions
salt.returners.postgres.prep_jid(nocache=False, passed_jid=None)¶Do any work necessary to prepare a JID, including sending a custom id
salt.returners.postgres.returner(ret)¶Return data to a postgres server
salt.returners.postgres.save_load(jid, load)¶Save the load to the specified jid id