Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ansible/roles/serverdensity
  • shrikeh/serverdensity
2 results
Show changes
Commits on Source (41)
The MIT License (MIT)
Copyright (c) 2014 Jürgen Haas
Copyright (c) 2015, 2016 Jürgen Haas, PARAGON Executive Services GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
SOFTWARE.
Ansible role to install and configure Server Density Agent
==========================================================
[Server Density] is a monitoring solution which requires a simple Python based agent and is highly configurable. This Ansible role installs and confgures that agent and supports several options like plugin installation and inventory synchronisation with your Server density dashboard.
Currently this plugin is developed and tested for Ubuntu only and will be enhanced to other Nix's later on.
##Dependency##
The [Ansible-ServerDensity-Plugin] is required and installation and instructions can be found in that project.
##Configuration##
In defaults/main.yml you'll find a set of variables that you could re-define in your own inventory. Please, do not overwrite the variables in defaults/main.yml, instead you should define them in your inventory files, e.g. group_vars/all
###sd_url###
Default: ```''```
Defines the Server Density URL of your account, e.g. ```'https://myaccount.serverdensity.io'```
###sd_api_token###
Default: ```''```
Defines your API token provided by Server Density. You get this token by going to preferences in your SD account to the "Security" tab where you can either grab one of the existing API tokens or createing a new one.
###sd_api_cache_file###
Default: ```false```
Each time you're using the SD plugin it reads the current settings for devices, services and alerts from your SD account by using the Server Density API. As this usually takes a couple of seconds it is possible to shortcut that process by storing all those settings in a cache file of your own choice so that next time those values get loaded from that cache file instead through the API.
The plugin makes sure that the cache gets reset if necessary, e.g. if the settings of your inventory have changed.
###sd_agent_key###
Default: ```''```
Do *not* redefine this variable, it is just there to avoid error messages in case a variable was missing. The agent key for each of your hosts gets assigned by Server Density and ill be imported by the plugin and will be used for updating your device settings.
###sd_logging_level###
Default: ```'info'```
Defines the level of log information that the SD agent will produce during run time. Possible values are debug, info, error, warn, warning, critical, fatal
###sd_plugins###
Default: ```[]```
Defines a list of Server Density plugins that will be installed and updated by this role automatically.
Example:
```
sd_plugins:
updatestatus: 'UpdateStatus.py'
redis: 'Redis.py'
```
This variable is expected to be defined as a set so that hash_behaviour=merge can be used so that you can define this variable in several of your groups and that this role is going to install the superset of all the group a specific host belings to.
The key of each entry should be unique across your inventory and the value is a file name. Those files have to be present in a subdirectory called ```files/sd-plugins``` of your inventory directory.
###sd_groups###
Default:
```
apache: 'none'
mysql: 'none'
proxy: 'none'
```
Certain sections in the agent configuration are only relevant for certain hosts and by providing valid inventory group names for those sections (currently apache, mysql, proxy) you can make sure that for all hosts in those groups the relevant parts in the agent configuration get written to that host.
##Detailed configuration for inventory synchronisation##
By defining further variables in your inventory, you get full control over how your inventory gets synchronized with your Server Density dashboard including device groups, services and alerts.
All those options are documented over in the [Ansible-ServerDensity-Plugin]
[Server Density]: https://www.serverdensity.com
[Ansible-ServerDensity-Plugin]: https://github.com/jurgenhaas/ansible-plugin-serverdensity
---
# file: roles/serverdensity/defaults/main.yml
sd_update_remote: true
sd_url: ''
sd_api_token: ''
sd_api_cache_file: false
sd_agent_key: ''
sd_logging_level: 'info'
sd_alert_cleanup: true
sd_force_update: true
sd_plugins: []
sd_update_remote: yes
sd_account:
sd_url:
sd_api_token:
sd_api_cache_file: no
sd_agent_key:
sd_logging_level: info
sd_alert_cleanup: no
sd_force_update: yes
sd_groups:
apache: 'none'
mysql: 'none'
proxy: 'none'
apache: none
mysql: none
proxy: none
sd_repo_public_key_uri: 'https://www.serverdensity.com/downloads/boxedice-public.key'
sd_agent_plugins_dir: '/usr/bin/sd-agent/plugins'
sd_plugins_files_dir: "{{ inventory_dir }}/files/sd-plugins"
sd_template_config: 'config.cfg'
sd_repo_public_key_uri: 'https://archive.serverdensity.com/sd-packaging-public.key'
sd_agent_plugins_dir: /usr/share/python/sd-agent/checks.d/plugins
sd_plugins_files_dir: "{{ playbook_dir }}/files/sd-plugins"
sd_uninstallv1: no
mysql_root_password: root
---
# file: roles/serverdensity/handlers/main.yml
- name: "ServerDensity | Restart Agent"
- name: Restart Agent
service:
name=sd-agent
state=restarted
name: sd-agent
state: restarted
- name: "ServerDensity | Restart Apache"
- name: Restart Apache
service:
name=apache2
state=restarted
name: apache2
state: restarted
......@@ -5,14 +5,14 @@ galaxy_info:
company: "PARAGON Executive Services GmbH"
min_ansible_version: 1.5
platforms:
- name: Ubuntu
versions:
- precise
- quantal
- raring
- saucy
- trusty
- name: Ubuntu
versions:
- precise
- quantal
- raring
- saucy
- trusty
categories:
- monitoring
- monitoring
dependencies: []
---
# file: roles/serverdensity/tasks/apache.yml
- name: "ServerDensity | Apache | Enable some required modules"
- name: Install The Agent
apt:
pkg: sd-agent-apache
state: present
notify:
- Restart Agent
- name: Configure The Agent
template:
src: apache.yaml
dest: /etc/sd-agent/conf.d/apache.yaml
owner: root
group: root
mode: 0644
notify:
- Restart Agent
- name: Enable some required modules
apache2_module:
name={{ item }}
state=present
name: '{{ item }}'
state: present
with_items:
- status
notify: "ServerDensity | Restart Apache"
notify:
- Restart Apache
- name: "ServerDensity | Apache | Configuration file for ServerDensity"
- name: Configuration file for ServerDensity
template:
src=etc-apache2-sites-available-sd-agent
dest=/etc/apache2/sites-available/sd-agent{{ apache_conf_ext }}
owner=root
group=root
mode=0644
notify: "ServerDensity | Restart Apache"
src: etc-apache2-sites-available-sd-agent
dest: /etc/apache2/sites-available/sd-agent{{ apache_conf_ext|default('.conf') }}
owner: root
group: root
mode: 0644
notify:
- Restart Apache
- name: "ServerDensity | Apache | Enable the sd-agent site"
command: a2ensite sd-agent creates=/etc/apache2/sites-enabled/sd-agent{{ apache_conf_ext }}
notify: "ServerDensity | Restart Apache"
- name: Enable the sd-agent site
command: a2ensite sd-agent
args:
creates: /etc/apache2/sites-enabled/sd-agent{{ apache_conf_ext|default('.conf') }}
notify:
- Restart Apache
---
# file: roles/serverdensity/tasks/main.yml
- name: 'ServerDensity | Init SD plugin'
local_action:
serverdensity
api_token={{sd_api_token}}
cleanup={{sd_alert_cleanup}}
force={{ sd_force_update }}
cache={{sd_api_cache_file}}
when: sd_update_remote
- name: ServerDensity Role
set_fact:
role_serverdensity_started: yes
tags:
- always
- name: 'ServerDensity | Install Public Repo Key'
apt_key:
url="{{ sd_repo_public_key_uri }}"
state=present
- block:
- name: 'ServerDensity | Add ServerDensity Repository To Apt'
copy:
content='deb http://www.serverdensity.com/downloads/linux/deb all main'
dest='/etc/apt/sources.list.d/sd-agent.list'
mode=644
- name: Import serverdensity
import_tasks: serverdensity.yml
when: sd_api_token != ''
- name: 'ServerDensity | Install The Agent'
apt:
pkg=sd-agent
state=installed
update_cache=yes
notify: 'ServerDensity | Restart Agent'
- name: 'ServerDensity | Create Plugins Directory'
file:
dest="{{ sd_agent_plugins_dir }}"
state=directory
mode=755
- name: 'ServerDensity | Copy Plugins'
copy:
src="{{ sd_plugins_files_dir }}/{{item.1}}"
dest="{{ sd_agent_plugins_dir }}/{{item.1}}"
with_items: sd_plugins|dictsort
when: sd_plugins|length > 0
notify: 'ServerDensity | Restart Agent'
- name: 'ServerDensity | Configure The Agent'
template: src="{{ sd_template_config }}"
dest=/etc/sd-agent/config.cfg
owner=root
group=root
mode=0644
when: sd_agent_key != ''
notify: 'ServerDensity | Restart Agent'
- include: apache.yml
when: sd_groups.apache != 'none' and inventory_hostname in groups[sd_groups.apache]
when: not excluded_roles or "serverdensity" not in excluded_roles
---
# file: roles/serverdensity/tasks/mysql.yml
- name: Install The Agent
apt:
pkg: sd-agent-mysql
state: present
notify:
- Restart Agent
- name: Configure The Agent
template:
src: mysql.yaml
dest: /etc/sd-agent/conf.d/mysql.yaml
owner: root
group: root
mode: 0644
notify:
- Restart Agent
---
# file: roles/serverdensity/tasks/serverdensity.yml
- name: Import uninstallv1
import_tasks: uninstallv1.yml
when: sd_uninstallv1
- name: Init SD plugin
serverdensity:
api_token: '{{ sd_api_token }}'
cleanup: '{{ sd_alert_cleanup }}'
force: '{{ sd_force_update }}'
cache: '{{ sd_api_cache_file }}'
delegate_to: localhost
when: sd_update_remote
- name: Install Public Repo Key
apt_key:
keyring: /etc/apt/trusted.gpg.d/serverdensity.gpg
url: '{{ sd_repo_public_key_uri }}'
state: present
- name: Add ServerDensity Repository To Apt
copy:
content: 'deb http://archive.serverdensity.com/ubuntu/ all main'
dest: /etc/apt/sources.list.d/sd-agent.list
mode: 0644
- name: Install The Agent
apt:
pkg: sd-agent
state: present
update_cache: yes
notify:
- Restart Agent
- name: Create Plugins Directory
file:
dest: '{{ sd_agent_plugins_dir }}'
state: directory
mode: 0755
- name: Copy Plugins
copy:
src: '{{ sd_plugins_files_dir }}/{{ item }}'
dest: '{{ sd_agent_plugins_dir }}/{{ item }}'
with_items: '{{ sd_plugins|default([]) }}'
notify:
- Restart Agent
- name: Configure The Agent
template:
src: '{{ item }}'
dest: '/etc/sd-agent/{{ item }}'
owner: root
group: root
mode: 0644
with_items:
- config.cfg
- plugins.cfg
# - supervisor.conf
when: sd_agent_key != ''
notify:
- Restart Agent
- name: Import apache
import_tasks: apache.yml
when: sd_groups.apache != 'none' and inventory_hostname in groups[sd_groups.apache]
- name: Import mysql
import_tasks: mysql.yml
when: sd_groups.mysql != 'none' and inventory_hostname in groups[sd_groups.mysql]
---
# file: roles/serverdensity/tasks/uninstallv1.yml
# Stop agent
- name: Stop v1 Agent
service:
name: sd-agent
state: stopped
# Uninstall agent
- name: Uninstall v1 Agent
apt:
pkg: sd-agent
state: absent
# Remove /usr/bin/sd-agent
- name: Remove Plugins Directory
file:
dest: /usr/bin/sd-agent
state: absent
init_config:
instances:
- apache_status_url: http://{{ inventory_hostname }}/server-status?auto
# Server Density Agent Config
# Docs: https://support.serverdensity.com/hc/en-us/articles/201003178-Agent-config-variables
# Plugins: http://plugins.serverdensity.com/
# Version 2
[Main]
sd_url: {{ sd_url }}
sd_account: {{ sd_account }}
agent_key: {{ sd_agent_key }}
plugin_directory: {{ sd_agent_plugins_dir }}
logging_level: {{ sd_logging_level }}
plugin_directory: {{ sd_agent_plugins_dir }}
{% if sd_groups.apache != 'none' and inventory_hostname in groups[sd_groups.apache] %}
# Apache
# See https://support.serverdensity.com/hc/en-us/articles/201253343-Apache-monitoring-Linux-Mac-and-FreeBSD
# ========================================================================== #
# Logging
# See https://support.serverdensity.com/hc/en-us/articles/213093038-Log-levels-agent-debug-mode
# ========================================================================== #
apache_status_url: http://{{ inventory_hostname }}/server-status/?auto
apache_status_user:
apache_status_pass:
{% endif %}
log_level: {{ sd_logging_level }}
{% if sd_groups.mysql != 'none' and inventory_hostname in groups[sd_groups.mysql] %}
# MySQL
# See https://support.serverdensity.com/hc/en-us/articles/201013827-MySQL-monitoring-Linux-Mac-and-FreeBSD
# collector_log_file: /var/log/sd-agent/collector.log
# forwarder_log_file: /var/log/sd-agent/forwarder.log
mysql_server: 127.0.0.1
mysql_user: root
mysql_pass: root
{% endif %}
{% if sd_groups.proxy != 'none' and inventory_hostname in groups[sd_groups.proxy] %}
haproxy_svname: {{ inventory_hostname }}
haproxy_url: http://127.0.0.1:7000/haproxy_stats
{% endif %}
# if syslog is enabled but a host and port are not set, a local domain socket
# connection will be attempted
#
# log_to_syslog: yes
# syslog_host:
# syslog_port:
<VirtualHost *:80>
<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 127.0.0.1{% for address in ansible_all_ipv4_addresses %} {{ address }}{% endfor %}
</Location>
ServerName {{ inventory_hostname }}
Include /etc/apache2/{{ apache_conf_dir|default('conf-available') }}/global-redirect.conf
ServerName {{ inventory_hostname }}
<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 127.0.0.1{% for address in ansible_all_ipv4_addresses %} {{ address }}{% endfor %}
</Location>
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
LogLevel warn
{% if apache_version|default('2.4') == '2.4' %}
ErrorLogFormat "[%{u}t] [%l] [pid %P] [client\ %{X-Forwarded-For}i] %M% ,\ referer:\ %{Referer}i"
{% endif %}
LogFormat "\"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined env=!forwarded
CustomLog ${APACHE_LOG_DIR}/access.log proxy env=forwarded
</VirtualHost>
init_config:
instances:
- server: 127.0.0.1
user: root
pass: {{ mysql_root_password }}
# PLugins config
{% if sd_groups.proxy != 'none' and inventory_hostname in groups[sd_groups.proxy] %}
[haproxy]
haproxy_svname: {{ inventory_hostname }}
haproxy_url: http://127.0.0.1:7000/haproxy_stats
{% endif %}
[supervisorctl]
serverurl = unix:///var/tmp/sd-supervisor.sock
[unix_http_server]
file=/var/tmp/sd-supervisor.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisord]
http_port = /var/tmp/sd-supervisor.sock
minfds = 1024
minprocs = 200
loglevel = info
logfile = /var/log/sd-agent/supervisord.log
logfile_maxbytes = 50MB
nodaemon = false
pidfile = /var/run/sd-supervisord.pid
logfile_backups = 10
environment=PYTHONPATH=/usr/share/python/sd-agent,LANG=POSIX
[program:collector]
command=/usr/share/python/sd-agent/bin/python /usr/share/python/sd-agent/agent.py foreground --use-local-forwarder
stdout_logfile=NONE
stderr_logfile=NONE
priority=999
startsecs=5
startretries=3
user=sd-agent
environment=PYTHONPATH='/usr/share/python/sd-agent:$PYTHONPATH'
[program:forwarder]
command=/usr/share/python/sd-agent/bin/python /usr/share/python/sd-agent/sdagent.py
stdout_logfile=NONE
stderr_logfile=NONE
startsecs=5
startretries=3
priority=998
user=sd-agent
[group:sd-agent]
programs=forwarder,collector