003 File Manager
Current Path:
/usr/local/lib/python3.8/site-packages/salt/returners
usr
/
local
/
lib
/
python3.8
/
site-packages
/
salt
/
returners
/
📁
..
📄
__init__.py
(5.98 KB)
📁
__pycache__
📄
appoptics_return.py
(6.11 KB)
📄
carbon_return.py
(8.24 KB)
📄
cassandra_cql_return.py
(15.17 KB)
📄
cassandra_return.py
(2.07 KB)
📄
couchbase_return.py
(8.91 KB)
📄
couchdb_return.py
(10.35 KB)
📄
django_return.py
(2.27 KB)
📄
elasticsearch_return.py
(12.18 KB)
📄
etcd_return.py
(6.32 KB)
📄
highstate_return.py
(15.59 KB)
📄
influxdb_return.py
(8.03 KB)
📄
kafka_return.py
(2.12 KB)
📄
librato_return.py
(4.29 KB)
📄
local.py
(541 B)
📄
local_cache.py
(17.1 KB)
📄
mattermost_returner.py
(4.08 KB)
📄
memcache_return.py
(5.72 KB)
📄
mongo_future_return.py
(10.08 KB)
📄
mongo_return.py
(6.11 KB)
📄
multi_returner.py
(2.82 KB)
📄
mysql.py
(18.61 KB)
📄
nagios_nrdp_return.py
(4.92 KB)
📄
odbc.py
(7.77 KB)
📄
pgjsonb.py
(17.18 KB)
📄
postgres.py
(10.2 KB)
📄
postgres_local_cache.py
(10.73 KB)
📄
pushover_returner.py
(6.55 KB)
📄
rawfile_json.py
(2.23 KB)
📄
redis_return.py
(8.52 KB)
📄
sentry_return.py
(5.3 KB)
📄
slack_returner.py
(6.02 KB)
📄
slack_webhook_return.py
(11.22 KB)
📄
sms_return.py
(2.64 KB)
📄
smtp_return.py
(8.2 KB)
📄
splunk.py
(6.69 KB)
📄
sqlite3_return.py
(7.73 KB)
📄
syslog_return.py
(5.26 KB)
📄
telegram_return.py
(1.92 KB)
📄
xmpp_return.py
(4.85 KB)
📄
zabbix_return.py
(2.45 KB)
Editing: influxdb_return.py
""" Return data to an influxdb server. .. versionadded:: 2015.8.0 To enable this returner the minion will need the python client for influxdb installed and the following values configured in the minion or master config, these are the defaults: .. code-block:: yaml influxdb.db: 'salt' influxdb.user: 'salt' influxdb.password: 'salt' influxdb.host: 'localhost' influxdb.port: 8086 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: .. code-block:: yaml alternative.influxdb.db: 'salt' alternative.influxdb.user: 'salt' alternative.influxdb.password: 'salt' alternative.influxdb.host: 'localhost' alternative.influxdb.port: 6379 To use the influxdb returner, append '--return influxdb' to the salt command. .. code-block:: bash salt '*' test.ping --return influxdb To use the alternative configuration, append '--return_config alternative' to the salt command. .. code-block:: bash salt '*' test.ping --return influxdb --return_config alternative To override individual configuration items, append --return_kwargs '{"key:": "value"}' to the salt command. .. versionadded:: 2016.3.0 .. code-block:: bash salt '*' test.ping --return influxdb --return_kwargs '{"db": "another-salt"}' """ import logging import requests import salt.returners import salt.utils.jid from salt.utils.decorators import memoize try: import influxdb import influxdb.influxdb08 HAS_INFLUXDB = True except ImportError: HAS_INFLUXDB = False # HTTP API header used to check the InfluxDB version influxDBVersionHeader = "X-Influxdb-Version" log = logging.getLogger(__name__) # Define the module's virtual name __virtualname__ = "influxdb" def __virtual__(): if not HAS_INFLUXDB: return ( False, "Could not import influxdb returner; " "influxdb python client is not installed.", ) return __virtualname__ def _get_options(ret=None): """ Get the influxdb options from salt. """ attrs = { "host": "host", "port": "port", "db": "db", "user": "user", "password": "password", } _options = salt.returners.get_returner_options( __virtualname__, ret, attrs, __salt__=__salt__, __opts__=__opts__ ) return _options @memoize def _get_version(host, port, user, password): version = None # check the InfluxDB version via the HTTP API try: result = requests.get( "http://{}:{}/ping".format(host, port), auth=(user, password) ) if influxDBVersionHeader in result.headers: version = result.headers[influxDBVersionHeader] except Exception as ex: # pylint: disable=broad-except log.critical( "Failed to query InfluxDB version from HTTP API within InfluxDB " "returner: %s", ex, ) return version def _get_serv(ret=None): """ Return an influxdb client object """ _options = _get_options(ret) host = _options.get("host") port = _options.get("port") database = _options.get("db") user = _options.get("user") password = _options.get("password") version = _get_version(host, port, user, password) if version and "v0.8" in version: return influxdb.influxdb08.InfluxDBClient( host=host, port=port, username=user, password=password, database=database ) else: return influxdb.InfluxDBClient( host=host, port=port, username=user, password=password, database=database ) def returner(ret): """ Return data to a influxdb data store """ serv = _get_serv(ret) # strip the 'return' key to avoid data duplication in the database json_return = salt.utils.json.dumps(ret["return"]) del ret["return"] json_full_ret = salt.utils.json.dumps(ret) # create legacy request in case an InfluxDB 0.8.x version is used if "influxdb08" in serv.__module__: req = [ { "name": "returns", "columns": ["fun", "id", "jid", "return", "full_ret"], "points": [ [ret["fun"], ret["id"], ret["jid"], json_return, json_full_ret] ], } ] # create InfluxDB 0.9+ version request else: req = [ { "measurement": "returns", "tags": {"fun": ret["fun"], "id": ret["id"], "jid": ret["jid"]}, "fields": {"return": json_return, "full_ret": json_full_ret}, } ] try: serv.write_points(req) except Exception as ex: # pylint: disable=broad-except log.critical("Failed to store return with InfluxDB returner: %s", ex) def save_load(jid, load, minions=None): """ Save the load to the specified jid """ serv = _get_serv(ret=None) # create legacy request in case an InfluxDB 0.8.x version is used if "influxdb08" in serv.__module__: req = [ { "name": "jids", "columns": ["jid", "load"], "points": [[jid, salt.utils.json.dumps(load)]], } ] # create InfluxDB 0.9+ version request else: req = [ { "measurement": "jids", "tags": {"jid": jid}, "fields": {"load": salt.utils.json.dumps(load)}, } ] try: serv.write_points(req) except Exception as ex: # pylint: disable=broad-except log.critical("Failed to store load with InfluxDB returner: %s", ex) def save_minions(jid, minions, syndic_id=None): # pylint: disable=unused-argument """ Included for API consistency """ def get_load(jid): """ Return the load data that marks a specified jid """ serv = _get_serv(ret=None) sql = "select load from jids where jid = '{}'".format(jid) log.debug(">> Now in get_load %s", jid) data = serv.query(sql) log.debug(">> Now Data: %s", data) if data: return data return {} def get_jid(jid): """ Return the information returned when the specified job id was executed """ serv = _get_serv(ret=None) sql = "select id, full_ret from returns where jid = '{}'".format(jid) data = serv.query(sql) ret = {} if data: points = data[0]["points"] for point in points: ret[point[3]] = salt.utils.json.loads(point[2]) return ret def get_fun(fun): """ Return a dict of the last function called for all minions """ serv = _get_serv(ret=None) sql = """select first(id) as fid, first(full_ret) as fret from returns where fun = '{}' group by fun, id """.format( fun ) data = serv.query(sql) ret = {} if data: points = data[0]["points"] for point in points: ret[point[1]] = salt.utils.json.loads(point[2]) return ret def get_jids(): """ Return a list of all job ids """ serv = _get_serv(ret=None) sql = "select distinct(jid) from jids group by load" # [{u'points': [[0, jid, load], # [0, jid, load]], # u'name': u'jids', # u'columns': [u'time', u'distinct', u'load']}] data = serv.query(sql) ret = {} if data: for _, jid, load in data[0]["points"]: ret[jid] = salt.utils.jid.format_jid_instance( jid, salt.utils.json.loads(load) ) return ret def get_minions(): """ Return a list of minions """ serv = _get_serv(ret=None) sql = "select distinct(id) from returns" data = serv.query(sql) ret = [] if data: for jid in data[0]["points"]: ret.append(jid[1]) return ret def prep_jid(nocache=False, passed_jid=None): # pylint: disable=unused-argument """ Do any work necessary to prepare a JID, including sending a custom id """ return passed_jid if passed_jid is not None else salt.utils.jid.gen_jid(__opts__)
Upload File
Create Folder