Skip to content

Commit 49e575e

Browse files
authored
Create check_purefa_hw.py
1 parent 3d8a572 commit 49e575e

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

check_purefa_hw.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env python3
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 current status of hardware components from a Pure Storage FlashArray.
33+
Hardware status indicators are collected from the target FA using the REST call.
34+
The plugin has threew mandatory arguments: 'endpoint', which specifies the target FA, 'apitoken', which
35+
specifies the autentication token for the REST call session and 'component', that is the name of the
36+
hardware component to be monitored. The component must be specified using the internal naming schema of
37+
the Pure FlashArray: i.e CH0 for the main chassis, CH1 for the secondary chassis (shelf 1), CT0 for controller 0,i
38+
CT1 for controller 1i, CH0.NVB0 for the first NVRAM module, CH0.NVB1 for the second NVRAM module, CH0.BAY0 for
39+
the first flash module, CH0.BAY10 for the tenth flash module, CH1.BAY1, for the first flash module on the
40+
first additional shelf,...
41+
42+
"""
43+
44+
import argparse
45+
import logging
46+
import nagiosplugin
47+
import purestorage
48+
import urllib3
49+
50+
51+
_log = logging.getLogger('nagiosplugin')
52+
53+
class PureFAhw(nagiosplugin.Resource):
54+
"""Pure Storage FlashArray overall occupancy
55+
56+
Calculates the overall FA storage occupancy
57+
58+
"""
59+
60+
def __init__(self, endpoint, apitoken, component):
61+
self.endpoint = endpoint
62+
self.apitoken = apitoken
63+
self.component = component
64+
65+
@property
66+
def name(self):
67+
return 'PURE_' + str(self.component)
68+
69+
def get_perf(self):
70+
"""Gets hardware element status from flasharray."""
71+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
72+
fa = purestorage.FlashArray(self.endpoint, api_token=self.apitoken)
73+
fainfo = fa.get_hardware(component=self.component)
74+
fa.invalidate_cookie()
75+
return(fainfo)
76+
77+
def probe(self):
78+
79+
fainfo = self.get_perf()
80+
_log.debug('FA REST call returned "%s" ', fainfo)
81+
status = fainfo.get('status')
82+
if (status == 'ok') or (status == 'not_installed'):
83+
metric = nagiosplugin.Metric(self.component + ' status', 0, context='default' )
84+
else:
85+
metric = nagiosplugin.Metric(self.component + ' status', 1, context='default')
86+
return metric
87+
88+
89+
def parse_args():
90+
argp = argparse.ArgumentParser()
91+
argp.add_argument('endpoint', help="FA hostname or ip address")
92+
argp.add_argument('apitoken', help="FA api_token")
93+
argp.add_argument('component', help="FA hardware component")
94+
argp.add_argument('-v', '--verbose', action='count', default=0,
95+
help='increase output verbosity (use up to 3 times)')
96+
argp.add_argument('-t', '--timeout', default=30,
97+
help='abort execution after TIMEOUT seconds')
98+
return argp.parse_args()
99+
100+
101+
@nagiosplugin.guarded
102+
def main():
103+
args = parse_args()
104+
check = nagiosplugin.Check( PureFAhw(args.endpoint, args.apitoken, args.component) )
105+
check.add(nagiosplugin.ScalarContext('default', 1, 1))
106+
check.main(args.verbose, args.timeout)
107+
108+
if __name__ == '__main__':
109+
main()

0 commit comments

Comments
 (0)