Skip to content

Commit 855057d

Browse files
authored
Create check_purefa_occpy.py
1 parent e03dc2c commit 855057d

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

check_purefa_occpy.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2018 Pure Storage, Inc.
3+
#
4+
## Overview
5+
#
6+
# This short Nagios/Icinga plugin code shows how to build a simple plugin to monitor Pure Storage FlashArrays.
7+
# The Pure Storage Python REST Client is used to query the FlashArray occupancy indicators.
8+
# Plugin leverages the remarkably helpful nagiosplugin library by Christian Kauhaus.
9+
#
10+
## Installation
11+
#
12+
# The scripo should be copied to the Nagios plugins directory on the machine hosting the Nagios server or the NRPE
13+
# for example the /usr/lib/nagios/plugins folder.
14+
# Change the execution rights of the program to allow the execution to 'all' (usually chmod 0755).
15+
#
16+
## Dependencies
17+
#
18+
# nagiosplugin helper Python class library for Nagios plugins by Christian Kauhaus (http://pythonhosted.org/nagiosplugin)
19+
# purestorage Pure Storage Python REST Client (https://github.com/purestorage/rest-client)
20+
21+
__author__ = "Eugenio Grosso"
22+
__copyright__ = "Copyright 2018, Pure Storage Inc."
23+
__credits__ = "Christian Kauhaus"
24+
__license__ = "Apache v2.0"
25+
__version__ = "1.0"
26+
__maintainer__ = "Eugenio Grosso"
27+
__email__ = "geneg@purestorage.com"
28+
__status__ = "Production"
29+
30+
"""Pure Storage FlashArray occupancy status
31+
32+
Nagios plugin to retrieve the overall occupancy from a Pure Storage FlashArray.
33+
Storage occupancy indicators are collected from the target FA using the REST call.
34+
35+
"""
36+
37+
import argparse
38+
import logging
39+
import nagiosplugin
40+
import purestorage
41+
import urllib3
42+
43+
44+
_log = logging.getLogger('nagiosplugin')
45+
46+
class PureFAoccpy(nagiosplugin.Resource):
47+
"""Pure Storage FlashArray overall occupancy
48+
49+
Calculates the overall FA storage occupancy
50+
51+
"""
52+
53+
def __init__(self, endpoint, apitoken):
54+
self.endpoint = endpoint
55+
self.apitoken = apitoken
56+
57+
def get_perf(self):
58+
"""Gets performance counters from flasharray."""
59+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
60+
fa = purestorage.FlashArray(self.endpoint, api_token=self.apitoken)
61+
fainfo = fa.get(space=True)[0]
62+
fa.invalidate_cookie()
63+
return(fainfo)
64+
65+
def probe(self):
66+
67+
fainfo = self.get_perf()
68+
_log.debug('FA REST call returned "%s" ', fainfo)
69+
occupancy = round(float(fainfo.get('total'))/float(fainfo.get('capacity')), 2) * 100
70+
metric = nagiosplugin.Metric('occupancy', occupancy, '%', min=0),
71+
return metric
72+
73+
74+
def parse_args():
75+
argp = argparse.ArgumentParser()
76+
argp.add_argument('endpoint', help="FA hostname or ip address")
77+
argp.add_argument('apitoken', help="FA api_token")
78+
argp.add_argument('-w', '--warning', metavar='RANGE', default='',
79+
help='return warning if occupancy is outside RANGE')
80+
argp.add_argument('-c', '--critical', metavar='RANGE', default='',
81+
help='return critical if occupancy is outside RANGE')
82+
argp.add_argument('-v', '--verbose', action='count', default=0,
83+
help='increase output verbosity (use up to 3 times)')
84+
argp.add_argument('-t', '--timeout', default=30,
85+
help='abort execution after TIMEOUT seconds')
86+
return argp.parse_args()
87+
88+
89+
@nagiosplugin.guarded
90+
def main():
91+
args = parse_args()
92+
check = nagiosplugin.Check( PureFAoccpy(args.endpoint, args.apitoken) )
93+
check.add(nagiosplugin.ScalarContext('occupancy', args.warning, args.critical))
94+
check.main(args.verbose, args.timeout)
95+
96+
if __name__ == '__main__':
97+
main()

0 commit comments

Comments
 (0)