File: check_cpu.py

package info (click to toggle)
pynag 0.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,196 kB
  • ctags: 1,181
  • sloc: python: 9,155; makefile: 200; sh: 151
file content (32 lines) | stat: -rwxr-xr-x 735 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
import os,sys

## Import plugin from nagios Module
from pynag.Plugins import simple as Plugin


## Create the plugin option
np = Plugin()

## Add a command line argument
np.add_arg("l","load-file", "Enter a load average file", required=None)

## This starts the actual plugin activation
np.activate()

## Use a custom load average file, if specified to
if np['load-file']:
    load_file = np['load-file']
else:
    load_file = "/proc/loadavg"

if not os.path.isfile(load_file):
    np.nagios_exit("UNKNOWN", "Missing Load average file %s" % load_file)

## Get the check value
current_load = open(load_file).readline().split()[0]

## Add the perdata
np.add_perfdata("1min", current_load)

np.check_range(current_load)