Skip to content

Commit

Permalink
Added python2.7 compatibility and fixed some formatting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
martinseener committed Dec 14, 2018
1 parent df2cb1c commit 52c3f34
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [1.0.1] - 2018-12-14
- made some fixes in the formatting/long lines using pycodestyle/pyflakes
- added compatibility for python 2.7

## [1.0.0] - 2018-12-09
- Initial release
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# check_hetzner_storage_box Icinga/Nagios check command
# check_hetzner_storage_box --- Icinga/Nagios check command

This check can be used with Icinga and Nagios and will check the free space of your Hetzner Storage Box and alerts you if it is below certain thresholds.

## Requirements

`check_hetzner_storage_box` requires Python 3.x to run and has been successfully tested with Python 3.4 on Debian and Python 3.7 on macOS.
`check_hetzner_storage_box` requires Python 2.7 or Python 3.x to run and has been successfully tested with Python 2.7/3.4 on Debian and Python 3.7 on macOS.

This check command depends on the following python modules:
* requests
* argparse

**Installation on Debian / Ubuntu**
```
# Python 2.x
apt install python-requests
# Python 3.x
apt install python3-requests
```

Expand Down
48 changes: 24 additions & 24 deletions check_hetzner_storage_box.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# # -*- coding: utf-8 -*-

"""
Expand All @@ -15,15 +15,15 @@
__author__ = 'Martin Seener'
__copyright__ = 'Copyright 2018, Martin Seener'
__license__ = 'MIT'
__version__ = '1.0.0'
__version__ = '1.0.1'
__maintainer__ = 'Martin Seener'
__email__ = 'martin@sysorchestra.com'
__email__ = 'martin[email protected]'
__status__ = 'Production'


def validate_storage_box(storage_box, user, password):
r = requests.get('https://robot-ws.your-server.de/storagebox/'
+ storage_box,
r = requests.get('https://robot-ws.your-server.de/storagebox/' +
storage_box,
auth=(user, password))
if r.status_code == 401:
print('UNKNOWN - Webservice is not enabled or user/password is wrong')
Expand All @@ -42,35 +42,35 @@ def validate_storage_box(storage_box, user, password):


def check_storage_box(storage_box, user, password, warning, critical):
r = requests.get('https://robot-ws.your-server.de/storagebox/'
+ storage_box,
r = requests.get('https://robot-ws.your-server.de/storagebox/' +
storage_box,
auth=(user, password))

disk_name = r.json()['storagebox']['name']
disk_quota = r.json()['storagebox']['disk_quota']
disk_usage = r.json()['storagebox']['disk_usage']
disk_quota = float(r.json()['storagebox']['disk_quota'])
disk_usage = float(r.json()['storagebox']['disk_usage'])
disk_free_percent = round(100 - (disk_usage / disk_quota) * 100, 1)

if disk_free_percent <= critical:
print('CRITICAL - Free disk size of Storage Box #{} ({}) is less than {}% of the quota!'.format(
storage_box,
disk_name,
critical
))
print('CRITICAL - Free disk size of Storage Box #{} ({}) '
'is less than {}% of the quota!'.format(storage_box,
disk_name,
critical)
)
sys.exit(2)
elif disk_free_percent <= warning:
print('WARNING - Free disk size of Storage Box #{} ({}) is less than {}% of the quota!'.format(
storage_box,
disk_name,
warning
))
print('WARNING - Free disk size of Storage Box #{} ({}) '
'is less than {}% of the quota!'.format(storage_box,
disk_name,
warning)
)
sys.exit(1)
elif warning < disk_free_percent:
print('OK - Free disk size of Storage Box #{} ({}) is currently {}%'.format(
storage_box,
disk_name,
disk_free_percent
))
print('OK - Free disk size of Storage Box #{} ({}) '
'is currently {}%'.format(storage_box,
disk_name,
disk_free_percent)
)
sys.exit()
else:
print('UNKNOWN - Unknown error occured!')
Expand Down

0 comments on commit 52c3f34

Please sign in to comment.