misc updates in states
This commit is contained in:
parent
4b9cf3759a
commit
be4f389ee6
@ -1,10 +1,9 @@
|
||||
#!/usr/pkg/bin/python2
|
||||
#-*- coding: utf-8 -*-
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import salt.modules.smtp
|
||||
import json
|
||||
import salt.modules.smtp
|
||||
|
||||
'''
|
||||
For use with salt reactor
|
||||
@ -17,7 +16,7 @@ def email_errors(fromaddr, toaddrs, subject, data_str, smtp_server):
|
||||
|
||||
try:
|
||||
if type(data['return']) is dict:
|
||||
for state, result in data['return'].iteritems():
|
||||
for _, result in data['return'].iteritems():
|
||||
if not result['result']:
|
||||
error = True
|
||||
break
|
||||
@ -27,25 +26,29 @@ def email_errors(fromaddr, toaddrs, subject, data_str, smtp_server):
|
||||
else:
|
||||
if not data['success']:
|
||||
error = True
|
||||
except KeyError as e:
|
||||
exit()
|
||||
except KeyError:
|
||||
sys.exit()
|
||||
|
||||
#if error or changes:
|
||||
if error:
|
||||
js = subprocess.check_output(["salt-run", "--out=json", "jobs.lookup_jid", data['jid']])
|
||||
if error or changes:
|
||||
_js = subprocess.check_output(["salt-run", "--out=json",
|
||||
"jobs.lookup_jid", data['jid']])
|
||||
body = "JobId is %s\n" % (data['jid'])
|
||||
outdata = json.loads(js)
|
||||
outdata = json.loads(_js)
|
||||
nodename = outdata.keys()[0]
|
||||
for i in outdata[nodename]:
|
||||
if not outdata[nodename][i]["result"]:
|
||||
name = outdata[nodename][i]["name"]
|
||||
comment = outdata[nodename][i]["comment"].rstrip('\n')
|
||||
data = "%s- %s / %s\n" % (body, name, comment)
|
||||
salt.modules.smtp.send_msg(recipient=toaddrs, message=data, subject=subject, sender=fromaddr, server=smtp_server, use_ssl=False)
|
||||
salt.modules.smtp.send_msg(recipient=toaddrs, message=data,
|
||||
subject=subject, sender=fromaddr,
|
||||
server=smtp_server, use_ssl=False)
|
||||
return True
|
||||
|
||||
def email_auth(fromaddr, toaddrs, subject, data_str, smtp_server):
|
||||
data = eval(data_str)
|
||||
salt.modules.smtp.send_msg(recipient=toaddrs, message=data, subject=subject, sender=fromaddr, server=smtp_server, use_ssl=False)
|
||||
salt.modules.smtp.send_msg(recipient=toaddrs, message=data,
|
||||
subject=subject, sender=fromaddr,
|
||||
server=smtp_server, use_ssl=False)
|
||||
|
||||
return True
|
@ -33,7 +33,7 @@ def enforce_custom_thing(name, foo, bar=True):
|
||||
|
||||
# Start with basic error-checking. Do all the passed parameters make sense
|
||||
# and agree with each-other?
|
||||
if bar == True and foo.startswith('Foo'):
|
||||
if bar and foo.startswith('Foo'):
|
||||
raise salt.exceptions.SaltInvocationError(
|
||||
'Argument "foo" cannot start with "Foo" if argument "bar" is True.')
|
||||
|
||||
|
@ -4,16 +4,16 @@ from __future__ import absolute_import, print_function, unicode_literals
|
||||
import salt.utils.dictupdate
|
||||
import salt.utils.dictdiffer
|
||||
|
||||
def jobs(name, url="http://localhost:8080", verify=False, jobs=[]):
|
||||
def jobs(name, url="http://localhost:8080", verify=False, job_list=[]):
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'Config is up to date'}
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'Config is up to date'}
|
||||
|
||||
#dk_jobs = []
|
||||
#dk_jobs = __salt__['dkron.get_jobs'](url, verify)
|
||||
|
||||
for job in jobs:
|
||||
for job in job_list:
|
||||
res = __salt__['dkron.set_jobs'](url, verify, job)
|
||||
if res is not None:
|
||||
ret['changes'][job['name']] = res
|
||||
|
@ -6,9 +6,9 @@ import salt.utils.dictdiffer
|
||||
|
||||
def config(name, verify, url, cfg):
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'config is up to date'}
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'config is up to date'}
|
||||
|
||||
cfg = dict(cfg)
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
[Unit]
|
||||
Description=The plugin-driven server agent for reporting metrics into InfluxDB
|
||||
Documentation=https://github.com/influxdata/telegraf
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=-/etc/default/telegraf
|
||||
#User=telegraf
|
||||
ExecStart=/usr/bin/telegraf --config $INFLUX_CONFIG
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
Restart=on-failure
|
||||
RestartForceExitStatus=SIGPIPE
|
||||
KillMode=control-group
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -5,4 +5,4 @@ dkron-jobs:
|
||||
- name: dkron-jobs
|
||||
- url: {{ dkron.url }}
|
||||
- verify: {{ dkron.verify }}
|
||||
- jobs: {{ dkron.jobs }}
|
||||
- job_list: {{ dkron.job_list }}
|
||||
|
Loading…
Reference in New Issue
Block a user