Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Webb committed Aug 24, 2017
0 parents commit 04c557d
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Idea
.idea
*.iml

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
bin/
*.zip

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2017 Dennis Webb

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, 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.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# OpenVPN DataDog Agent

Adds OpenVPN licensing stats to DataDog.

![](../master/screenshot.png)

## Installation

### Automated

The included [install.sh](install.sh) script will copy the files to the correct locations, give `dd-agent` permissions to interact with OpenVPN, and restart the agent.

### Manual

1. Copy [openvpn.py](openvpn.py) to `/etc/dd-agent/checks.d`
2. Copy [openvpn.yaml](openvpn.yaml) to `/etc/dd-agent/conf.d`
3. Add `dd-agent ALL=NOPASSWD: /usr/local/openvpn_as/scripts/sacli` to `/etc/sudoers` using `visudo`
4. Restart the agent with `/etc/init.d/datadog-agent restart`
2 changes: 2 additions & 0 deletions build_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
zip datadog-openvpn.zip *.py *.yaml *.md install.sh
6 changes: 6 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cp openvpn.py /etc/dd-agent/checks.d/openvpn.py
cp openvpn.yaml /etc/dd-agent/conf.d/openvpn.yaml

echo 'dd-agent ALL=NOPASSWD: /usr/local/openvpn_as/scripts/sacli' | sudo EDITOR='tee -a' visudo

/etc/init.d/datadog-agent restart
28 changes: 28 additions & 0 deletions openvpn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import ast
from checks import AgentCheck
from subprocess import check_output


class OpenVPN(AgentCheck):


def check(self, instance):
metric_prefix = self.init_config.get('metric_prefix', 'openvpn')
license_usage = self.get_license_usage()
self.gauge('%s.licenses_used' % metric_prefix, license_usage['used'])
self.gauge('%s.licenses_available' % metric_prefix, license_usage['available'])
self.gauge('%s.licenses_total' % metric_prefix, license_usage['total'])


def get_license_usage(self):
sacli_path = self.init_config.get('sacli_path', '/usr/local/openvpn_as/scripts/sacli')
lic_usage = ast.literal_eval(check_output(["sudo", sacli_path, "LicUsage"]))
return {
'used': lic_usage[0],
'total': lic_usage[1],
'available': lic_usage[1] - lic_usage[0]
}


if __name__ == '__main__':
check.check(instance)
7 changes: 7 additions & 0 deletions openvpn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
init_config:
metric_prefix: openvpn
sacli_path: /usr/local/openvpn_as/scripts/sacli

instances:
[{}]

Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 04c557d

Please sign in to comment.