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

Commit 0a95715

Browse files
authored
Merge pull request #101 from madflojo/develop
2017.06 Release
2 parents 55da07d + 6c994e2 commit 0a95715

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+276
-2320
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Before starting to contribute to Automatron please review and accept our [Contri
1010

1111
Contributing to the Core platform and contributing Plugins have two different guidelines and requirements. The below will explain some basic concepts of how to contribute different functionality.
1212

13-
### Core
13+
### Contributing to Core
1414

1515
Automatron follows a pluggable architecture with the majority of features being provided by plugins located within the `plugins/` directory. This allows us to keep the Core framework minimal and simple.
1616

@@ -23,10 +23,12 @@ At this time there are 4 primary core components of Automatron.
2323

2424
These components are written in Python and as such should follow basic Python development practices.
2525

26-
### Plugins
26+
### Contributing Plugins
2727

2828
Where the Automatron Core provides a monitoring and actioning framework, the functional features are all provided by Automatron Plugins. Plugins, are the fastest way to add features to Automatron. As such it is suggested that new contributors start by adding a plugin before adding core functionality.
2929

30+
Plugin contributions have been migrated to the [Automatron Plugins](https://github.com/Automatron-Plugins) project. Pull Requests for existing plugins should be opened against the appropriate repository in that project. Requests for new plugin repositories can be made via [Gitter](https://gitter.im/madflojo/automatron).
31+
3032
#### Executable Plugins
3133

3234
At this time there are 6 types of Plugins.
@@ -39,7 +41,7 @@ At this time there are 6 types of Plugins.
3941
* `vetting` - Executables used to identify `facts` for discovered monitoring targets.
4042

4143
While `datastores`, `logging`, and `discovery` plugins are Python modules; `actions`, `checks` and `vetting` are simply executables.
42-
Python is the preferred approach however, these plugins may also be written in Perl or BASH. While other languages are accepted it is important to ensure capabilities are available across as many platforms as possible. When writing plugins do consider the availability of functionality on generic systems.
44+
These plugins may be written in Python, Perl, BASH or any language that results in a standalone executable.
4345

4446
## Contribution Workflow & Requirements
4547

@@ -58,17 +60,15 @@ When opening a Pull Request for a bug fix, if the fix is for the current release
5860

5961
If the bug fix should also be incorporated with the `develop` branch a second Pull Request should be opened to the `develop` branch.
6062

61-
### Tests are required for Core and some Plugins
63+
### Tests are required for Core
6264

6365
Any Pull Requests for the Automatron core code base should include applicable `unit`, `integration` and `functional` tests. Automatron uses Coveralls to ensure code coverage does not decrease with each Pull Request.
6466

65-
While not strictly enforced, plugins should also include tests where applicable. In some cases it may not be possible to provide `unit` or `integration` tests for plugins. In these cases it is recommended to create `functional` tests.
66-
6767
### Documentation is required
6868

69-
Documentation of new functionality is important to increase the adoption of Automatron. As such, you may be asked to provide documentation for new functionality created by your Pull Request. This is especially true for new plugins being submitted as plugins must be documented in order for users to adopt the plugin.
69+
Documentation of new functionality is important to increase the adoption of Automatron. As such, you may be asked to provide documentation for new functionality created by your Pull Request. This is especially true for major feature changes.
7070

71-
Documentation is just as important as new functionality, as such documentation based pull requests are encouraged. For idea's on current gaps please reference our [documentation board](https://github.com/madflojo/automatron/projects/1).
71+
Documentation is just as important as new functionality, as such documentation based pull requests are encouraged.
7272

7373
## Developer environment
7474

config/config.yml.example

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,9 @@ discovery:
3535
webping:
3636
ip: 0.0.0.0
3737
port: 8000
38-
# nmap:
39-
# # NMAP Scanning for new hosts
40-
# target: 10.0.0.1/8
41-
# flags: -sP
42-
# interval: 40
43-
# digitalocean:
44-
# # Query DO's API
45-
# url: https://api.digitalocean.com/v2
46-
# api_key: example
47-
# interval: 60
48-
# aws:
49-
# # Query AWS' API
50-
# aws_access_key_id: example
51-
# aws_secret_access_key: example
52-
# interval: 60
53-
# filter:
54-
# - PublicIpAddress
55-
# - PrivateIpAddress
56-
# linode:
57-
# # Query Linode's API
58-
# url: https://api.linode.com
59-
# api_key: example
60-
# interval: 60
38+
# roster:
39+
# hosts:
40+
# - 10.0.0.1
6141

6242
## Datastore
6343
datastore:

config/runbooks/examples/cpu/idle.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Check CPU Idle
2+
schedule:
3+
seconds: "*/30"
4+
checks:
5+
cpu_idle:
6+
execute_from: target
7+
type: cmd
8+
cmd: test $(sar -u 1 1 | tail -n 1 | awk '{print $8}' | cut -d. -f1) -gt 10
9+
actions:
10+
logger:
11+
execute_from: target
12+
type: cmd
13+
cmd: echo "CPU Idle at critical threshold: `sar -u 1 1 | tail -n 1 | awk '{print $8}' | cut -d. -f1`" | logger -t automatron
14+
trigger: 0
15+
frequency: 120
16+
call_on:
17+
- CRITICAL
18+
- WARNING
19+
- UNKNOWN
20+
reboot:
21+
execute_from: target
22+
type: cmd
23+
cmd: reboot
24+
trigger: 20
25+
frequency: 900
26+
call_on:
27+
- WARNING
28+
- CRITICAL
29+
- UNKNOWN

config/runbooks/examples/disk_free/init.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

config/runbooks/examples/docker/clear_dangling_images.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Clean up dangling images if they are found
2-
schedule: "*/2 * * * *"
2+
schedule: "0 */2 * * *"
33
checks:
44
find_danglers:
55
execute_from: ontarget

config/runbooks/examples/docker/init.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Verify Docker is running
2-
schedule: "* * * * *"
2+
schedule: "*/2 * * * *"
33
checks:
44
docker_running:
55
execute_from: ontarget

config/runbooks/examples/nginx/init.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

docs/configure.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ If the `gateway` setting is left as `False` Automatron will login to each host d
3939

4040
By default, Automatron will listen on port `8000` for any HTTP requests. When an HTTP request is made to Automatron the IP will be captured and that server will then be identified as a monitoring target.
4141

42-
There are several plugins that enable other methods for host discovery, in this section we will enable the `nmap` discovery plugin. This configuration is within the `discovery` section of the `config.yml` file.
42+
There are several plugins that enable other methods for host discovery, in this section we will also enable the `roster` discovery plugin. This configuration is within the `discovery` section of the `config.yml` file.
4343

4444
```yaml+jinja
4545
discovery:
@@ -52,7 +52,7 @@ discovery:
5252
port: 8000
5353
```
5454

55-
To enable the `nmap` plugin we simply need to append the `nmap` configuration within the `plugins` key.
55+
To enable the `roster` plugin we simply need to append the `roster` configuration within the `plugins` key.
5656

5757
```yaml+jinja
5858
discovery:
@@ -64,12 +64,11 @@ discovery:
6464
ip: 0.0.0.0
6565
port: 8000
6666
# NMAP Scanning
67-
nmap:
68-
target: 10.0.0.1/8
69-
flags: -sP
70-
interval: 40
67+
roster:
68+
hosts:
69+
- 10.0.0.1
7170
```
7271

73-
Each plugin has unique configuration details, the specifics of these plugins can be found in the [plugin](plugins/index.md) documentation.
72+
Each plugin has unique configuration details, additional discovery plugins can be found in the [Automatron Plugins](https://github.com/Automatron-Plugins) project.
7473

7574
At this point Automatron has been configured. We can now move on to creating our own [Runbooks](runbooks/index.md).

docs/facts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Auomatron leverages the power of [Jinja2](http://jinja.pocoo.org/docs/2.9/), a popular Python based templating language to enhance how runbooks can be used. The below example is a runbook that leverages Jinja2.
1+
Automatron leverages the power of [Jinja2](http://jinja.pocoo.org/docs/2.9/), a popular Python based templating language to enhance how runbooks can be used. The below example is a runbook that leverages Jinja2.
22

33
```yaml+jinja
44
name: Check NGINX
@@ -44,7 +44,7 @@ actions:
4444

4545
The above runbook leverages both Jinja2 and Automatron's internal **Facts**. Facts are variables that Automatron has collected during the Vetting process of each monitored system.
4646

47-
When Automatron discovers a new host it executes [Vetting Plugins](plugins/#Vetting) on the host. Some plugins are executed remotely, others are executed on the host itself. These plugins return information unique to each host.
47+
When Automatron discovers a new host it executes Vetting Plugins on the host. Some plugins are executed remotely, others are executed on the host itself. These plugins return information unique to each host.
4848

4949
An example of the type of information can be seen in the `ontarget/system_info.py` vetting plugin. This plugin creates facts for OS Distribution, Hostname, Kernel version and Network Information.
5050

docs/plugins/actions.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Actions can be as simple as a one-liner shell command or as complicated as a 1,000 line Python script. With Automatron's action plugins both of these scenarios can be covered.
2+
3+
Automatron action plugins are simply executables that are copied and executed on the specified target. There is no special language or coding syntax required other than the fact that the script should be executable without specifying the language.
4+
5+
## A simple example
6+
7+
To understand this further let's write a simple plugin that finds files that require a `dos2unix` conversion and converts them. Before getting into our script, let's start with a runbook for this example.
8+
9+
```yaml+jinja
10+
name: Check if application has started
11+
schedule:
12+
second: "*/30"
13+
checks:
14+
port_443_is_up:
15+
execute_from: target
16+
type: plugin
17+
plugin: network/tcp_connect.py
18+
args: --host=localhost --port 443
19+
actions:
20+
dos2unix_files:
21+
execute_from: target
22+
trigger: 0
23+
frequency: 900
24+
call_on:
25+
- WARNING
26+
- CRITICAL
27+
- UNKNOWN
28+
type: plugin
29+
plugin: custom/dos2unix.sh
30+
args: /application/path
31+
```
32+
33+
The above runbook will verify if the application is listening on port 443 and if not execute the `dos2unix_files` action. This action is a plugin action which will copy the `plugins/actions/custom/dos2unix.sh` script to the target server and execute it with the argument of `/application/path`. To explain this better, the below command represents how this plugin would be executed on the target server.
34+
35+
```sh
36+
$ custom/dos2unix.sh /application/path
37+
```
38+
39+
This script itself can be very simple and only needs to accept the arguments passed.
40+
41+
### Sample code
42+
43+
The below script is a sample script that will perform a `dos2unix` conversion on any files within the specified path.
44+
45+
```bash
46+
#!/bin/bash
47+
48+
if [ -z $1 ]
49+
then
50+
echo "Usage: $0 /path"
51+
exit 1
52+
fi
53+
54+
BEFORE=$(find $1 -type f -exec file {} \; | grep -c "with CRLF line terminators")
55+
56+
for FILE in `find $1 -type f -exec file {} \; | grep "with CRLF line terminators" | cut -d: -f1`
57+
do
58+
dos2unix $FILE
59+
done
60+
61+
AFTER=$(find $1 -type f -exec file {} \; | grep -c "with CRLF line terminators")
62+
63+
if [ $AFTER -lt $BEFORE ]
64+
then
65+
exit 0
66+
else
67+
exit 1
68+
fi
69+
```
70+
71+
The exit codes used by the action plugin will be used by Automatron to determine successful action execution or a failed action execution. A script that is successful should exit with a code of `0`. Any other exit code will show as a failed action execution.
72+
73+
!!! info
74+
Automatron action plugins are designed to be as simple as possible to allow users to use their existing scripts along with Automatron's automated action execution. Aside from appropriate exit code usage there is no coding required to use an existing script or utility.

0 commit comments

Comments
 (0)