Skip to content

Commit

Permalink
Merge pull request #26 from NETWAYS/refactor
Browse files Browse the repository at this point in the history
Major Refactor to allow future maintainability
  • Loading branch information
martialblog committed Jul 7, 2023
2 parents 5768191 + e9734c6 commit 8bd68e3
Show file tree
Hide file tree
Showing 11 changed files with 1,124 additions and 423 deletions.
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Contributing
Before starting your work on this module, you should [fork the project] to your GitHub account. This allows you to
freely experiment with your changes. When your changes are complete, submit a [pull request]. All pull requests will be
reviewed and merged if they suit some general guidelines:

* Changes are located in a topic branch
* For new functionality, proper tests are written
* Changes should not solve certain problems on special environments

## Branches
Choosing a proper name for a branch helps us identify its purpose and possibly find an associated bug or feature.
Generally a branch name should include a topic such as `fix` or `feature` followed by a description and an issue number
if applicable. Branches should have only changes relevant to a specific issue.

```
git checkout -b fix/service-template-typo-1234
git checkout -b feature/config-handling-1235
git checkout -b doc/fix-typo-1236
```

## Testing
Python modules are unit tested with the Python Standard Library. When modifying existing modules or tasks, make sure all existing tests pass. If you add new functionality, make sure to write appropriate tests as well.

[fork the project]: https://help.github.com/articles/fork-a-repo/
[pull request]: https://help.github.com/articles/using-pull-requests/
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

lint:
python -m pylint check_bareos

test:
python -m unittest -v -b
python -m unittest -v test_check_bareos.py
coverage:
python -m coverage run -m unittest test_check_bareos.py
python -m coverage report -m --include check_bareos.py
210 changes: 176 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,197 @@

Icinga Monitoring Plugin to check Bareos Backup Director databases

## Setup
The plugin connects to the Bareos database in order to retrieve data.

## Installation

The plugin requires at least Python 3.

Python dependencies:

* `psycopg2-binary`

## Usage

```
p check_bareos.py --help
usage: check_bareos.py [-h] -U USER [-p PASSWORD] [-H HOST] [-P PORT] [-d DATABASE] [-v]
{job,tape,status} ...
Check Plugin for Bareos Backup Status
positional arguments:
{job,tape,status}
job Specific checks on a job
tape Specific checks on a tapes
status Specific status informations
options:
-h, --help show this help message and exit
Requires Python 3 to be installed.
-U USER, --user USER user name for the database connections
-p PASSWORD, --password PASSWORD
password for the database connections
-H HOST, --Host HOST database host
-P PORT, --port PORT database port
-d DATABASE, --database DATABASE
database name
-v, --version show program's version number and exit
```

Depending on your database setup either `requirements-mysql.txt` or `requirements-postgres.txt` needs to be installed.
## Job

Check the status of Bareos Jobs.

```
usage: check_bareos.py job [-h] (-js | -j | -rt) [-n NAME] [-t TIME] [-u {GB,TB,PB}] [-w WARNING]
[-c CRITICAL] [-st {A,B,C,D,E,F,I,L,M,R,S,T,W,a,c,d,e,f,i,j,l,m,p,q,s,t}]
[-f] [-i] [-d]
options:
-h, --help show this help message and exit
-js, --checkJobs Check how many jobs are in a specific state [default=queued]
-j, --checkJob Check the state of a specific job [default=queued]
-rt, --runTimeJobs Check if a backup runs longer then n day
-n NAME, --name NAME Name of the job
-t TIME, --time TIME Time in days (default=7 days)
-u {GB,TB,PB}, --unit {GB,TB,PB}
display unit
-w WARNING, --warning WARNING
Warning value
-c CRITICAL, --critical CRITICAL
Critical value
-st {A,B,C,D,E,F,I,L,M,R,S,T,W,a,c,d,e,f,i,j,l,m,p,q,s,t}, --state {A,B,C,D,E,F,I,L,M,R,S,T,W,a,c,d,e,f,i,j,l,m,p,q,s,t}
Bareos Job State [default=C]
-f, --full Backup kind full
-i, --inc Backup kind inc
-d, --diff Backup kind diff
```

### Examples

Check if a job is runing longar than 7 days (default value):

```bash
check_bareos.py job -rt -t 4 -st R -w 1 -c 4
```

Check how much jobs are in the wating status:

```bash
check_bareos.py job -js -w 50 -c 100
```

## Tape

# Examples
Check the status of Bareos Tapes.

Note: use the postgresql database bareos and login without password
```
usage: check_bareos.py tape [-h] (-e | -ts | -ex | -wex | -r) [-w WARNING] [-c CRITICAL] [-m MOUNTS]
[-t TIME]
#### Check if a full backup has 0 Bytes(is Empty) and trigger warning it is at least 1 and trigger ciritcal if more than 5 are empty
```check_bareos.py -u bareos -d p status -e -f -w 1 -c 5```
options:
-h, --help show this help message and exit
-e, --emptyTapes Count empty tapes in the storage (Status Purged/Expired)
-ts, --tapesInStorage
Count how much tapes are in the storage
-ex, --expiredTapes Count how much tapes are expired
-wex, --willExpire Count how much tapes are will expire in n day
-r, --replaceTapes Count how much tapes should by replaced
-w WARNING, --warning WARNING
Warning value
-c CRITICAL, --critical CRITICAL
Critical value
-m MOUNTS, --mounts MOUNTS
Amout of allowed mounts for a tape [used for replace tapes]
-t TIME, --time TIME Time in days (default=7 days)
```

### Examples

Check how much tapes are empty in the storage:

```bash
check_bareos.py tape -e -w 15 -c 10
```

Check how much tapes are expired:

```
check_bareos.py tape -ex
```

Check how much tapes will expire in the next 14 days;

```bash
check_bareos.py tape -wex -t 14 -w 10 -c 5
```

## Status

Check the status of various Bareos metrics.

```
usage: check_bareos.py status [-h] (-b | -e | -o | -fb) [-f] [-i] [-d] [-t TIME] [-w WARNING]
[-c CRITICAL] [-s SIZE] [-u {MB,GB,TB,PB,EB}]
options:
-h, --help show this help message and exit
-b, --totalBackupsSize
the size of all backups in the database [use time and kind for mor
restrictions]
-e, --emptyBackups Check if a successful backup have 0 bytes [only wise for full backups]
-o, --oversizedBackup
Check if a backup have more than n TB
-fb, --failedBackups Check if a backup failed in the last n day
-f, --full Backup kind full
-i, --inc Backup kind inc
-d, --diff Backup kind diff
-t TIME, --time TIME Time in days
-w WARNING, --warning WARNING
Warning value [default=5]
-c CRITICAL, --critical CRITICAL
Critical value [default=10]
-s SIZE, --size SIZE Border value for oversized backups [default=2]
-u {MB,GB,TB,PB,EB}, --unit {MB,GB,TB,PB,EB}
display unit [default=TB]
```

### Examples

#### Check if a diff/inc backup is larger than 2 TB (default value) and trigger warning it is at least 1 and trigger ciritcal if more than 5 are empty
```check_bareos.py -u bareos -d p status -o -d -i -w 1 -c 5```

Check total size of all backups:

#### Check how much tapes are empty in the storage
```check_bareos.py -u bareos -d p tape -e -w 15 -c 10```
```bash
check_bareos.py status -b -w 400 -c 500
```

Check total size of all full backups:

#### Check total size of all backups
```check_bareos.py -u bareos -d p status -b -w 400 -c 500```
```bash
check_bareos.py status -b -f -w 400 -c 500
```

Check total size of all diff backups:

#### Check total size of all full backups
```check_bareos.py -u bareos -d p status -b -f -w 400 -c 500```
```bash
check_bareos.py status -b -d -w 400 -c 500
```

Check total size of all inc backups:

#### Check total size of all diff backups
```check_bareos.py -u bareos -d p status -b -d -w 400 -c 500```
```bash
check_bareos.py status -b -i -w 400 -c 500
```

Check if a full backup has 0 Bytes(is Empty) and trigger warning it is at least 1 and trigger ciritcal if more than 5 are empty:

#### Check total size of all inc backups
```check_bareos.py -u bareos -d p status -b -i -w 400 -c 500```
```bash
check_bareos.py status -e -f -w 1 -c 5
```


#### Check if a job is runing longar than 7 days (default value)
```check_bareos.py -u bareos -d p job -rt -t 4 -st R -w 1 -c 4```


#### Check how much jobs are in the wating status
```check_bareos.py -u bareos -d p job -js -w 50 -c 100```


#### Check how much tapes are expired
```check_bareos.py -u bareos -d p tape -ex```


#### Check how much tapes will expire in the next 14 days
```check_bareos.py -u bareos -d p tape -wex -t 14 -w 10 -c 5```
Check if a diff/inc backup is larger than 2 TB (default value) and trigger warning it is at least 1 and trigger ciritcal if more than 5 are empty:

```bash
check_bareos.py status -o -d -i -w 1 -c 5
```
Loading

0 comments on commit 8bd68e3

Please sign in to comment.