Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #126 from madflojo/develop
Browse files Browse the repository at this point in the history
New Release Develop to Master
  • Loading branch information
madflojo authored Sep 2, 2018
2 parents 5a3ccfe + 824f776 commit 59a7050
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 16 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu:latest
RUN apt-get update --fix-missing && \
apt-get -y upgrade && \
apt-get -y install \
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get upgrade -y && apt-get -y install \
tzdata \
python-pip \
python-dev \
nmap \
Expand All @@ -10,6 +10,7 @@ RUN apt-get update --fix-missing && \
build-essential \
libssl-dev && \
rm -rf /var/lib/apt/lists/*
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && dpkg-reconfigure --frontend noninteractive tzdata
ADD requirements.txt /
RUN pip install --upgrade setuptools pip
RUN pip install -r /requirements.txt
Expand Down
18 changes: 10 additions & 8 deletions actioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ def get_runbooks_to_exec(item, target, logger):
trigger = target['runbooks'][item['runbook']]['actions'][action]['trigger']
frequency = target['runbooks'][item['runbook']]['actions'][action]['frequency']
last_run = 0
run_once = False
if "last_run" in target['runbooks'][item['runbook']]['actions'][action]:
last_run = target['runbooks'][item['runbook']]['actions'][action]['last_run']
if "run_once" in target['runbooks'][item['runbook']]['actions'][action]:
run_once = target['runbooks'][item['runbook']]['actions'][action]['run_once']

# see if we are beyond or equal to trigger threshold
for status in call_on:
Expand All @@ -122,6 +125,11 @@ def get_runbooks_to_exec(item, target, logger):
if item['checks'][check] not in call_on:
run_me = False

# checking if run_once action was already run
if last_run != 0 and run_once:
logger.debug("Action {} was already run once and will not run again".format(action))
run_me = False # turns False as action has already run

if run_me is True:
run_these[item['runbook']].add(action)
return run_these
Expand Down Expand Up @@ -190,13 +198,7 @@ def execute_runbook(action, target, config, logger):
logger.debug("Could not execute command {0}".format(cmd))

# Check results
if results:
if results.succeeded is True:
return True
else:
return False
else:
return False
return results.succeeded

def shutdown(signum, frame):
''' Shutdown this process '''
Expand All @@ -213,7 +215,7 @@ def shutdown(signum, frame):
if __name__ == "__main__":
config = core.common.get_config(description="Automatron: Actioning")
if config is False:
print "Could not get configuration"
print("Could not get configuration")
sys.exit(1)

# Setup Logging
Expand Down
2 changes: 1 addition & 1 deletion discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def shutdown(signum, frame):
# pylint: disable=C0103
config = core.common.get_config(description="Automatron: Discovery")
if config is False:
print "Could not get configuration"
print("Could not get configuration")
sys.exit(1)

# Setup Logging
Expand Down
9 changes: 9 additions & 0 deletions docs/runbooks/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ actions:
host: 10.0.0.2
trigger: 0
frequency: 300
run_once: False
call_on:
- WARNING
- CRITICAL
Expand All @@ -98,6 +99,14 @@ The `frequency` field is used to specify the time (in seconds) between action ex

If you wish to execute an action every time, simply set this value to `0` seconds.

### Run Once (OPTIONAL)

The optional `run_once` field is a boolean used to determine if the action will run only once. If set to `True`, the action will run only the first time the `trigger` condition is met and will not run again until it's back to its normal state.

Defaults to `False`.

Note: the action will run once everytime the health check fails and the `trigger` condition is met. For example, if the check returns `WARNING`, then `OK` and then `WARNING` again, the `run_once` action will run one time for each failure.

### Call on

The `call_on` field is a YAML list which is used to list the states that should trigger this action. Valid options are `OK`, `WARNING`, `CRITICAL` & `UNKNOWN`.
Expand Down
2 changes: 1 addition & 1 deletion monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def shutdown(signum, frame):
if __name__ == "__main__":
config = core.common.get_config(description="Automatron: Monitoring")
if config is False:
print "Could not get configuration"
print("Could not get configuration")
sys.exit(1)

# Setup Logging
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ python-libnmap
gevent-websocket
redis
apscheduler
fabric
fabric<2
pyYAML
jinja2
mock
Expand Down
2 changes: 1 addition & 1 deletion runbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def shutdown(signum, frame):
if __name__ == "__main__":
config = core.common.get_config(description="Automatron: Runbooks")
if config is False:
print "Could not get configuration"
print("Could not get configuration")
sys.exit(1)

# Setup Logging
Expand Down
2 changes: 1 addition & 1 deletion web.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_targets(target=None):
if __name__ == '__main__':
config = core.common.get_config(description="Automatron: Web")
if config is False:
print "Could not get configuration"
print("Could not get configuration")
sys.exit(1)
app.config.update(config)

Expand Down

0 comments on commit 59a7050

Please sign in to comment.