Skip to content

Commit d8d7fc5

Browse files
authored
Update check_purefa_occpy.py
1 parent 687d76f commit d8d7fc5

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

check_purefa_occpy.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# Copyright (c) 2018 Pure Storage, Inc.
33
#
44
## Overview
@@ -29,8 +29,13 @@
2929

3030
"""Pure Storage FlashArray occupancy status
3131
32-
Nagios plugin to retrieve the overall occupancy from a Pure Storage FlashArray.
32+
Nagios plugin to retrieve the overall occupancy from a Pure Storage FlashArray or from a single volume.
3333
Storage occupancy indicators are collected from the target FA using the REST call.
34+
The plugin has two mandatory arguments: 'endpoint', which specifies the target FA and 'apitoken', which
35+
specifies the autentication token for the REST call session. A third optional parameter, 'volname' can
36+
be used to check a specific named value. The optional values for the warning and critical thresholds have
37+
different meausure units: they must be expressed as percentages in the case of checkig the whole flasharray
38+
occupancy, while they must be integer byte units if checking a single volume.
3439
3540
"""
3641

@@ -44,41 +49,59 @@
4449
_log = logging.getLogger('nagiosplugin')
4550

4651
class PureFAoccpy(nagiosplugin.Resource):
47-
"""Pure Storage FlashArray overall occupancy
52+
"""Pure Storage FlashArray occupancy
4853
49-
Calculates the overall FA storage occupancy
54+
Calculates the overall FA storage occupancy or a single volume capacity.
5055
5156
"""
5257

53-
def __init__(self, endpoint, apitoken):
58+
def __init__(self, endpoint, apitoken, volname):
5459
self.endpoint = endpoint
5560
self.apitoken = apitoken
61+
self.volname = volname
62+
63+
@property
64+
def name(self):
65+
if (self.volname is None):
66+
return 'PURE_FA_OCCUPANCY'
67+
else:
68+
return 'PURE_VOL_OCCUPANCY'
69+
5670

5771
def get_perf(self):
58-
"""Gets capacity counters from flasharray."""
72+
"""Gets performance counters from flasharray."""
5973
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
6074
fa = purestorage.FlashArray(self.endpoint, api_token=self.apitoken)
61-
fainfo = fa.get(space=True)[0]
75+
if (self.volname is None):
76+
fainfo = fa.get(space=True)[0]
77+
else:
78+
fainfo = fa.get_volume(self.volname, space=True)
79+
6280
fa.invalidate_cookie()
6381
return(fainfo)
6482

6583
def probe(self):
6684

6785
fainfo = self.get_perf()
6886
_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, max=100)
87+
if (self.volname is None):
88+
occupancy = round(float(fainfo.get('total'))/float(fainfo.get('capacity')), 2) * 100
89+
metric = nagiosplugin.Metric('FA occupancy', occupancy, '%', min=0, max=100, context='occupancy')
90+
else:
91+
occupancy = int(fainfo.get('volumes'))
92+
metric = nagiosplugin.Metric(self.volname + ' occupancy', occupancy, 'B', min=0, context='occupancy')
7193
return metric
7294

7395

7496
def parse_args():
7597
argp = argparse.ArgumentParser()
7698
argp.add_argument('endpoint', help="FA hostname or ip address")
7799
argp.add_argument('apitoken', help="FA api_token")
100+
argp.add_argument('--vol', help="FA volume name. If omitted the whole FA occupancy is cecked")
78101
argp.add_argument('-w', '--warning', metavar='RANGE', default='',
79-
help='return warning if occupancy is outside RANGE')
102+
help='return warning if occupancy is outside RANGE. Value has to be expressed in percentage for the FA, while in bytes for the single volume')
80103
argp.add_argument('-c', '--critical', metavar='RANGE', default='',
81-
help='return critical if occupancy is outside RANGE')
104+
help='return critical if occupancy is outside RANGE. Value has to be expressed in percentage for the FA, while in bytes for the single volume')
82105
argp.add_argument('-v', '--verbose', action='count', default=0,
83106
help='increase output verbosity (use up to 3 times)')
84107
argp.add_argument('-t', '--timeout', default=30,
@@ -89,7 +112,7 @@ def parse_args():
89112
@nagiosplugin.guarded
90113
def main():
91114
args = parse_args()
92-
check = nagiosplugin.Check( PureFAoccpy(args.endpoint, args.apitoken) )
115+
check = nagiosplugin.Check( PureFAoccpy(args.endpoint, args.apitoken, args.vol) )
93116
check.add(nagiosplugin.ScalarContext('occupancy', args.warning, args.critical))
94117
check.main(args.verbose, args.timeout)
95118

0 commit comments

Comments
 (0)