Skip to content

Commit

Permalink
Improved README / Check for dependencies
Browse files Browse the repository at this point in the history
Updated README and added check for python dependencies. Also updated
icinga2 command and service defintions
  • Loading branch information
Nicolai Buchwitz committed Jan 17, 2018
1 parent d65dc85 commit e4d5f5d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 67 deletions.
109 changes: 50 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
# check_pve
Icinga check command for Proxmox VE via API

## installation / dependencies
### Debian / Ubuntu
## Requirements

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

**Installation on Debian / Ubuntu**
```
apt install python-enum34 python-requests
```

### Redhat / CentOS
**Installation on Redhat 6 / CentOS 6**
```
yum install python-argparse python-enum34 python-requests
```

**Installation on Redhat 7 / CentOS 7**
```
yum install python-enum34 python-requests
```

## usage
## Usage

The ``icinga2`` folder contains the command defintion and service examples for use with Icinga2.

```
usage: check_pve.py [-h] -e API_ENDPOINT -u API_USER -p API_PASSWORD [-k] -m
{cluster,cpu,memory,storage,io_wait,updates,services,subscription,vm}
Expand All @@ -28,7 +42,8 @@ API Options:
-e API_ENDPOINT, --api-endpoint API_ENDPOINT
PVE api endpoint hostname
-u API_USER, --username API_USER
PVE api user (e.g. icinga2@pve or icinga2@pam, depending on which backend you have chosen in proxmox)
PVE api user (e.g. icinga2@pve or icinga2@pam,
depending on which backend you have chosen in proxmox)
-p API_PASSWORD, --password API_PASSWORD
PVE api user password
-k, --insecure Don't verify HTTPS certificate
Expand All @@ -48,74 +63,50 @@ Check Options:
also treated as MB values
```

# hints

Try something like that first ...
## Examples

**Check cluster health**
```
./check_pve.py -u icinga2@pve -p uoXei8fee9shia4tah4voobe -e proxmox.localdomain.local -k -m cluster
./check_pve.py -u <API_USER> -p <API_PASSWORD> -e <API_ENDPOINT> -m cluster
OK - Cluster 'proxmox1' is healthy'
```

## Get cluster health
**Check CPU load**
```
./check_pve.py -u <API_USER> -p <API_PASSWORD> -e <API_ENDPOINT> -k -m cluster
OK - Cluster 'proxmox1' is healthy'
./check_pve.py -u <API_USER> -p <API_PASSWORD> -e <API_ENDPOINT> -m memory -n node1
OK - CPU usage is 2.4%|usage=2.4%;;
```

## Get CPU load
**Check memory usage**
```
./check_pve.py -u <API_USER> -p <API_PASSWORD> -e <API_ENDPOINT> -k -m cpu -n node1
OK - CPU usage is 2.4%|usage=2.4%;;
./check_pve.py -u <API_USER> -p <API_PASSWORD> -e <API_ENDPOINT> -m cpu -n node1
OK - Memory usage is 25.55%|usage=25.55%;; used=49415.93MB;;;193403.4
```

## Get storage usage
**Check storage usage**
```
./check_pve.py -u <API_USER> -p <API_PASSWORD> -e <API_ENDPOINT> -k -m storage -n node1 --name local
./check_pve.py -u <API_USER> -p <API_PASSWORD> -e <API_ENDPOINT> -m storage -n node1 --name local
OK - Storage usage is 54.23%|usage=54.23%;; used=128513.11MB;;;236980.36
```

# faq
## AttributeError: 'int' object has no attribute 'name'
### Problem
```
Traceback (most recent call last):
File "/usr/lib/nagios/plugins/check_pve.py", line 419, in <module>
pve.check()
File "/usr/lib/nagios/plugins/check_pve.py", line 359, in check
self.checkOutput()
File "/usr/lib/nagios/plugins/check_pve.py", line 59, in checkOutput
self.output(self.checkResult, message)
File "/usr/lib/nagios/plugins/check_pve.py", line 62, in output
prefix = returnCode.name
AttributeError: 'int' object has no attribute 'name'
```

### Solution
Be sure, python-enum34 (enum34) is installed.
https://docs.python.org/3/library/enum.html#creating-an-enum

##
### Problem
```
Traceback (most recent call last):
File "/usr/lib/nagios/plugins/check_pve.py", line 418, in <module>
pve = CheckPVE()
File "/usr/lib/nagios/plugins/check_pve.py", line 415, in __init__
self.getTicket()
File "/usr/lib/nagios/plugins/check_pve.py", line 115, in getTicket
result = self.request(url, "post", data=data)
File "/usr/lib/nagios/plugins/check_pve.py", line 96, in request
self.output(NagiosState.UNKNOWN, "Could not connect to PVE API: Failed to resolve hostname")
File "/usr/lib/nagios/plugins/check_pve.py", line 62, in output
prefix = returnCode.name
AttributeError: 'int' object has no attribute 'name'
```
### Solution
Check the connection with curl
```
curl -k -d "username=<API_USER>&password=<API_PASSWORD>" https://<API_ENDPOINT>:8006/api2/json/access/ticket
```
Maybee a proxy (http_proxy, https_proxy) env variable blocks the connection to your proxmox host
**Check subscription status**
```
./check_pve.py -u <API_USER> -p <API_PASSWORD> -e <API_ENDPOINT> -m subscription -n node1
OK - Subscription of level 'Community' is valid until 2019-01-09
```

**Check VM status**
```
./check_pve.py -u <API_USER> -p <API_PASSWORD> -e <API_ENDPOINT> -m vm -n node1 --name test-vm
OK - VM 'test-vm' is running|cpu=1.85%;; memory=8.33%;;
```

## FAQ

### Could not connect to PVE API: Failed to resolve hostname

Verify that your DNS server is working and can resolve your hostname. If everything is fine check for proxyserver environment variables (HTTP_PROXY,HTTPS_PROXY), which maybe not allow communication to port 8006.




20 changes: 13 additions & 7 deletions check_pve.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@

from __future__ import print_function
import sys
from enum import Enum
from datetime import datetime
import argparse
import requests
import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
try:
from enum import Enum
from datetime import datetime
import argparse
import requests
import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
except ImportError as e:
print("Missing python module: {}".format(e.message))
sys.exit(255)


class NagiosState(Enum):
Expand Down Expand Up @@ -364,7 +369,8 @@ def parseOptions(self):
api_opts = p.add_argument_group('API Options')

api_opts.add_argument("-e", "--api-endpoint", required=True, help="PVE api endpoint hostname")
api_opts.add_argument("-u", "--username", dest='api_user', required=True, help="PVE api user")
api_opts.add_argument("-u", "--username", dest='api_user', required=True,
help="PVE api user (e.g. icinga2@pve or icinga2@pam, depending on which backend you have chosen in proxmox)")
api_opts.add_argument("-p", "--password", dest='api_password', required=True, help="PVE api user password")
api_opts.add_argument("-k", "--insecure", dest='api_insecure', action='store_true', default=False,
help="Don't verify HTTPS certificate")
Expand Down
2 changes: 1 addition & 1 deletion icinga2/command.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object CheckCommand "pve" {
"-m" = {
value = "$pve_mode$"
required = true
description = "Check mode (cluster, updates, subscription, storage, cpu, memory, io_wait)"
description = "Check mode (cluster, updates, subscription, storage, cpu, memory, io_wait, vm)"
}
"-n" = {
value = "$pve_node$"
Expand Down
2 changes: 2 additions & 0 deletions icinga2/service.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object Host "proxmox-host.domain.example" {
pve_warning = 80
pve_critical = 90
}

vars.pve_storage["diskpool"] = {
pve_unit = "%"
pve_warning = 80
Expand All @@ -34,6 +35,7 @@ object Host "proxmox-host.domain.example" {

template Service "pve-service" {
import "generic-service"

check_command = "pve"
}

Expand Down

0 comments on commit e4d5f5d

Please sign in to comment.