check_naf.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. #####################################################################
  4. # (c) 2006-2010 by Sven Velt and team(ix) GmbH, Nuernberg, Germany #
  5. # sv@teamix.net #
  6. # #
  7. # This file is part of check_naf (FKA check_netappfiler) #
  8. # #
  9. # check_naf is free software: you can redistribute it and/or modify #
  10. # it under the terms of the GNU General Public License as published #
  11. # by the Free Software Foundation, either version 2 of the License, #
  12. # or (at your option) any later version. #
  13. # #
  14. # check_naf is distributed in the hope that it will be useful, but #
  15. # WITHOUT ANY WARRANTY; without even the implied warranty of #
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  17. # GNU General Public License for more details. #
  18. # #
  19. # You should have received a copy of the GNU General Public License #
  20. # along with check_naf. If not, see <http://www.gnu.org/licenses/>. #
  21. #####################################################################
  22. from monitoringplugin import SNMPMonitoringPlugin
  23. class CheckNAF(SNMPMonitoringPlugin):
  24. OID = {
  25. 'Cluster_Settings': '.1.3.6.1.4.1.789.1.2.3.1.0',
  26. 'Cluster_State': '.1.3.6.1.4.1.789.1.2.3.2.0',
  27. 'Cluster_InterconnectStatus': '.1.3.6.1.4.1.789.1.2.3.8.0',
  28. 'Cluster_CannotTakeOverCause': '.1.3.6.1.4.1.789.1.2.3.3.0',
  29. 'CPU_Arch': '.1.3.6.1.4.1.789.1.1.11.0',
  30. 'CPU_Time_Busy': '.1.3.6.1.4.1.789.1.2.1.3.0',
  31. 'CPU_Time_Idle': '.1.3.6.1.4.1.789.1.2.1.5.0',
  32. 'CPU_Context_Switches': '.1.3.6.1.4.1.789.1.2.1.8.0',
  33. 'Disks_Total': '.1.3.6.1.4.1.789.1.6.4.1.0',
  34. 'Disks_Active': '.1.3.6.1.4.1.789.1.6.4.2.0',
  35. 'Disks_Reconstructing': '.1.3.6.1.4.1.789.1.6.4.3.0',
  36. 'Disks_ReconstParity': '.1.3.6.1.4.1.789.1.6.4.4.0',
  37. 'Disks_Scrubbing': '.1.3.6.1.4.1.789.1.6.4.6.0',
  38. 'Disks_Failed': '.1.3.6.1.4.1.789.1.6.4.7.0',
  39. 'Disks_Spare': '.1.3.6.1.4.1.789.1.6.4.8.0',
  40. 'Disks_ZeroDisks': '.1.3.6.1.4.1.789.1.6.4.9.0',
  41. 'Disks_Failed_Descr': '.1.3.6.1.4.1.789.1.6.4.10.0',
  42. 'ExtCache_Type': '.1.3.6.1.4.1.789.1.26.1.0',
  43. 'ExtCache_SubType': '.1.3.6.1.4.1.789.1.26.2.0',
  44. 'ExtCache_Size': '.1.3.6.1.4.1.789.1.26.4.0',
  45. 'ExtCache_Usedsize': '.1.3.6.1.4.1.789.1.26.5.0',
  46. 'ExtCache_Options': '.1.3.6.1.4.1.789.1.26.7.0',
  47. 'ExtCache_Hits': '.1.3.6.1.4.1.789.1.26.8.0',
  48. 'ExtCache_Misses': '.1.3.6.1.4.1.789.1.26.9.0',
  49. 'ExtCache_Inserts': '.1.3.6.1.4.1.789.1.26.10.0',
  50. 'ExtCache_Evicts': '.1.3.6.1.4.1.789.1.26.11.0',
  51. 'ExtCache_Invalidates': '.1.3.6.1.4.1.789.1.26.12.0',
  52. 'ExtCache_MetaData': '.1.3.6.1.4.1.789.1.26.15.0',
  53. 'Global_Status': '.1.3.6.1.4.1.789.1.2.2.4.0',
  54. 'Global_Status_Message': '.1.3.6.1.4.1.789.1.2.2.25.0',
  55. 'NVRAM_Status': '.1.3.6.1.4.1.789.1.2.5.1.0',
  56. 'Model': '.1.3.6.1.4.1.789.1.1.5.0',
  57. 'ONTAP_Version': '.1.3.6.1.4.1.789.1.1.2.0',
  58. 'df_FS_Index': '.1.3.6.1.4.1.789.1.5.4.1.1',
  59. 'df_FS_Name': '.1.3.6.1.4.1.789.1.5.4.1.2',
  60. 'df_FS_Mounted_On': '.1.3.6.1.4.1.789.1.5.4.1.10',
  61. 'df_FS_Status': '.1.3.6.1.4.1.789.1.5.4.1.20',
  62. 'df_FS_Type': '.1.3.6.1.4.1.789.1.5.4.1.23',
  63. 'df_FS_kBTotal': ['.1.3.6.1.4.1.789.1.5.4.1.29', '.1.3.6.1.4.1.789.1.5.4.1.15', '.1.3.6.1.4.1.789.1.5.4.1.14',],
  64. 'df_FS_kBUsed': ['.1.3.6.1.4.1.789.1.5.4.1.30', '.1.3.6.1.4.1.789.1.5.4.1.17', '.1.3.6.1.4.1.789.1.5.4.1.16',],
  65. 'df_FS_kBAvail': ['.1.3.6.1.4.1.789.1.5.4.1.31', '.1.3.6.1.4.1.789.1.5.4.1.19', '.1.3.6.1.4.1.789.1.5.4.1.18',],
  66. 'df_FS_INodeUsed': '.1.3.6.1.4.1.789.1.5.4.1.7',
  67. 'df_FS_INodeFree': '.1.3.6.1.4.1.789.1.5.4.1.8',
  68. 'df_FS_MaxFilesAvail': '.1.3.6.1.4.1.789.1.5.4.1.11',
  69. 'df_FS_MaxFilesUsed': '.1.3.6.1.4.1.789.1.5.4.1.12',
  70. 'df_FS_MaxFilesPossible': '.1.3.6.1.4.1.789.1.5.4.1.13',
  71. }
  72. OWC = {
  73. 'Cluster_InterconnectStatus': ( (4,), (3,), (1,2,), ),
  74. 'Cluster_Settings': ( (2,), (1,3,4,), (5,), ),
  75. 'Cluster_State': ( (2,4,), (), (1,3,), ),
  76. 'Global_Status': ( (3,), (4,), (5,6), ),
  77. 'NVRAM_Status': ( (1,9), (2,5,8), (3,4,6), ),
  78. }
  79. Status2String = {
  80. 'Cluster_CannotTakeOverCause': { '1' : 'ok', '2' : 'unknownReason', '3' : 'disabledByOperator', '4' : 'interconnectOffline', '5' : 'disabledByPartner', '6' : 'takeoverFailed', },
  81. 'Cluster_InterconnectStatus': { '1' : 'notPresent', '2' : 'down', '3' : 'partialFailure', '4' : 'up', },
  82. 'Cluster_Settings': { '1' : 'notConfigured', '2' : 'enabled', '3' : 'disabled', '4' : 'takeoverByPartnerDisabled', '5' : 'thisNodeDead', },
  83. 'Cluster_State': { '1' : 'dead', '2' : 'canTakeover', '3' : 'cannotTakeover', '4' : 'takeover', },
  84. 'CPU_Arch' : { '1' : 'x86', '2' : 'alpha', '3' : 'mips', '4' : 'sparc', '5' : 'amd64', },
  85. 'NVRAM_Status' : { '1' : 'ok', '2' : 'partiallyDischarged', '3' : 'fullyDischarged', '4' : 'notPresent', '5' : 'nearEndOfLife', '6' : 'atEndOfLife', '7' : 'unknown', '8' : 'overCharged', '9' : 'fullyCharged', },
  86. 'df_FS_Status' : { '1' : 'unmounted', '2' : 'mounted', '3' : 'frozen', '4' : 'destroying', '5' : 'creating', '6' : 'mounting', '7' : 'unmounting', '8' : 'nofsinfo', '9' : 'replaying', '10': 'replayed', },
  87. 'df_FS_Type' : { '1' : 'traditionalVolume', '2' : 'flexibleVolume', '3' : 'aggregate', },
  88. }
  89. def map_status_to_returncode(self, value, mapping):
  90. for returncode in xrange(0,3):
  91. if value in mapping[returncode]:
  92. return returncode
  93. return 3
  94. def check_cpu(self, warn='', crit=''):
  95. cpu_arch = self.SNMPGET(self.OID['CPU_Arch'])
  96. cpu_timebusy = int(self.SNMPGET(self.OID['CPU_Time_Busy']))
  97. # cputimeidle = int(self.SNMPGET(self.OID['CPU_Time_Idle']))
  98. cpu_cs = self.SNMPGET(self.OID['CPU_Context_Switches'])
  99. if '%' in warn:
  100. warn = warn[:-1]
  101. if '%' in crit:
  102. crit = crit[:-1]
  103. returncode = self.value_wc_to_returncode(cpu_timebusy, warn, crit)
  104. output = 'CPU ' + str(cpu_timebusy) + '% busy, CPU architecture: ' + self.Status2String['CPU_Arch'].get(cpu_arch)
  105. perfdata = []
  106. pd = {'label':'nacpu', 'value':cpu_timebusy, 'unit':'%', 'min':0, 'max':100}
  107. if warn:
  108. pd['warn'] = warn
  109. if crit:
  110. pd['crit'] = crit
  111. perfdata.append(pd)
  112. perfdata.append({'label':'nacs', 'value':cpu_cs, 'unit':'c'})
  113. return self.remember_check('cpu', returncode, output, perfdata=perfdata)
  114. def check_cluster(self):
  115. cl_settings = int(self.SNMPGET(self.OID['Cluster_Settings']))
  116. if cl_settings == 1: # notConfigured
  117. return self.remember_check('cluster', self.RETURNCODE['WARNING'], 'No cluster configured!')
  118. cl_state = int(self.SNMPGET(self.OID['Cluster_State']))
  119. cl_interconnectstatus = int(self.SNMPGET(self.OID['Cluster_InterconnectStatus']))
  120. returncode = []
  121. returncode.append(self.map_status_to_returncode(cl_settings, self.OWC['Cluster_Settings']))
  122. returncode.append(self.map_status_to_returncode(cl_state, self.OWC['Cluster_State']))
  123. returncode.append(self.map_status_to_returncode(cl_interconnectstatus, self.OWC['Cluster_InterconnectStatus']))
  124. returncode = max(returncode)
  125. output = 'Settings: ' + self.Status2String['Cluster_Settings'][str(cl_settings)] + ', '
  126. output += 'state: ' + self.Status2String['Cluster_State'][str(cl_state)] + ', '
  127. output += 'interconnect state: ' + self.Status2String['Cluster_InterconnectStatus'][str(cl_interconnectstatus)]
  128. if cl_state == 4: # cannotTakeover
  129. cl_cannottakeovercause = self.SNMPGET(self.OID['Cluster_CannotTakeOverCause'])
  130. output = 'Cannot takeover, reason: ' + self.Status2String['Cluster_CannotTakeOverCause'][cl_cannottakeovercause] + '! ' + output
  131. return self.remember_check('cluster', returncode, output)
  132. def check_disk(self, target='failed', warn='', crit=''):
  133. di_total = int(self.SNMPGET(self.OID['Disks_Total']))
  134. di_active = int(self.SNMPGET(self.OID['Disks_Active']))
  135. di_reconstructing = int(self.SNMPGET(self.OID['Disks_Reconstructing']))
  136. di_reconstparity = int(self.SNMPGET(self.OID['Disks_ReconstParity']))
  137. # di_scrubbing = int(self.SNMPGET(self.OID['Disks_Scrubbing']))
  138. di_failed = int(self.SNMPGET(self.OID['Disks_Failed']))
  139. di_spare = int(self.SNMPGET(self.OID['Disks_Spare']))
  140. # di_zerodisks = int(self.SNMPGET(self.OID['Disks_ZeroDisks']))
  141. di_reconstr = di_reconstructing + di_reconstparity
  142. if target == 'spare':
  143. returncode = self.value_wc_to_returncode(di_spare, warn, crit)
  144. output = str(di_spare) + ' spare disk'
  145. if di_spare > 1:
  146. output += 's'
  147. else:
  148. target = 'failed' # Set to defined value
  149. returncode = self.value_wc_to_returncode(di_failed, warn, crit)
  150. if returncode == 0:
  151. output = 'No failed disks'
  152. else:
  153. output = self.SNMPGET(self.OID['Disks_Failed_Descr'])
  154. perfdata = []
  155. perfdata.append({'label':'nadisk_total', 'value':di_total, 'unit':'', 'min':0})
  156. perfdata.append({'label':'nadisk_active', 'value':di_active, 'unit':'', 'min':0})
  157. pd = {'label':'nadisk_spare', 'value':di_spare, 'unit':'', 'min':0}
  158. if warn and target=='spare':
  159. pd['warn'] = warn
  160. if crit and target=='spare':
  161. pd['crit'] = crit
  162. perfdata.append(pd)
  163. pd = {'label':'nadisk_failed', 'value':di_failed, 'unit':'', 'min':0}
  164. if warn and target=='failed':
  165. pd['warn'] = warn
  166. if crit and target=='failed':
  167. pd['crit'] = crit
  168. perfdata.append(pd)
  169. return self.remember_check('disk', returncode, output, perfdata=perfdata, target=target)
  170. def check_extcache(self):
  171. if self.options.snmpversion in [1, '1']:
  172. return self.remember_check('extcache', self.RETURNCODE['UNKNOWN'], 'Need SNMP v2c/v3 for "extcache" check!',)
  173. ec_size = long(self.SNMPGET(self.OID['ExtCache_Size']))
  174. ec_usedsize = long(self.SNMPGET(self.OID['ExtCache_Usedsize']))
  175. ec_hits = long(self.SNMPGET(self.OID['ExtCache_Hits']))
  176. # ec_meta = long(self.SNMPGET(self.OID['ExtCache_MetaData']))
  177. ec_miss = long(self.SNMPGET(self.OID['ExtCache_Misses']))
  178. ec_evict = long(self.SNMPGET(self.OID['ExtCache_Evicts']))
  179. ec_inval = long(self.SNMPGET(self.OID['ExtCache_Invalidates']))
  180. ec_insert = long(self.SNMPGET(self.OID['ExtCache_Inserts']))
  181. ec_usage = float(ec_usedsize) / float(ec_size) * 100.0
  182. ec_hitpct = float(ec_hits) / float(ec_hits + ec_miss) * 100.0
  183. ec_size_human = self.value_to_human_binary(ec_size, unit='B')
  184. output = 'Cache size %s, cache usage %5.2f%%, total hits %5.2f%% ' % (ec_size_human, ec_usage, ec_hitpct)
  185. returncode = 0
  186. perfdata = []
  187. perfdata.append({'label':'nacache_usage', 'value':float('%5.2f' % ec_usage), 'unit':'%'})
  188. perfdata.append({'label':'nacache_hits', 'value':ec_hits, 'unit':'c'})
  189. perfdata.append({'label':'nacache_miss', 'value':ec_miss, 'unit':'c'})
  190. perfdata.append({'label':'nacache_evict', 'value':ec_evict, 'unit':'c'})
  191. perfdata.append({'label':'nacache_inval', 'value':ec_inval, 'unit':'c'})
  192. perfdata.append({'label':'nacache_insert', 'value':ec_insert, 'unit':'c'})
  193. return self.remember_check('extcache', returncode, output, perfdata=perfdata)
  194. def check_extcache_info(self):
  195. ec_type = self.SNMPGET(self.OID['ExtCache_Type'])
  196. ec_subtype = self.SNMPGET(self.OID['ExtCache_SubType'])
  197. ec_size = long(self.SNMPGET(self.OID['ExtCache_Size']))
  198. ec_options = self.SNMPGET(self.OID['ExtCache_Options'])
  199. ec_size_human = self.value_to_human_binary(ec_size, unit='B')
  200. output = 'Cache type: "' + ec_type + '/' + ec_subtype + '", size: ' + ec_size_human + ', options: "' + ec_options + '"'
  201. returncode = 0
  202. return self.remember_check('extcache_info', returncode, output)
  203. def check_global(self):
  204. model = self.SNMPGET(self.OID['Model'])
  205. globalstatus = int(self.SNMPGET(self.OID['Global_Status']))
  206. globalstatusmsg = self.SNMPGET(self.OID['Global_Status_Message'])[:255]
  207. returncode = self.map_status_to_returncode(globalstatus, self.OWC['Global_Status'])
  208. output = model + ': ' + globalstatusmsg
  209. return self.remember_check('global', returncode, output)
  210. def check_nvram(self):
  211. nvramstatus = int(self.SNMPGET(self.OID['NVRAM_Status']))
  212. returncode = self.map_status_to_returncode(nvramstatus, self.OWC['NVRAM_Status'])
  213. output = 'NVRAM battery status is "' + self.Status2String['NVRAM_Status'].get(str(nvramstatus)) + '"'
  214. return self.remember_check('nvram', returncode, output)
  215. def check_version(self):
  216. model = self.SNMPGET(self.OID['Model'])
  217. ontapversion = self.SNMPGET(self.OID['ONTAP_Version'])
  218. return self.remember_check('version', 0, model + ': ' + ontapversion)
  219. def common_vol_idx(self, volume):
  220. if volume.endswith('.snapshot'):
  221. return None
  222. idx = str(self.find_in_table(self.OID['df_FS_Index'], self.OID['df_FS_Name'] , volume))
  223. sn_idx = int(idx) + 1
  224. return (idx, sn_idx)
  225. def check_vol_data(self, volume, warn, crit):
  226. (idx, sn_idx) = self.common_vol_idx(volume)
  227. fs_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], idx)) * 1024L
  228. fs_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], idx)) * 1024L
  229. # fs_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], idx)) * 1024L
  230. sn_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], sn_idx)) * 1024L
  231. sn_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], sn_idx)) * 1024L
  232. # sn_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], sn_idx)) * 1024L
  233. mountedon = self.SNMPGET(self.OID['df_FS_Mounted_On'] + "." + idx)
  234. status = self.Status2String['df_FS_Status'].get(self.SNMPGET(self.OID['df_FS_Status'] + "." + idx))
  235. fstype = self.Status2String['df_FS_Type'].get(self.SNMPGET(self.OID['df_FS_Type'] + "." + idx))
  236. fs_pctused = float(fs_used) / float(fs_total) * 100.0
  237. warn = self.range_dehumanize(warn, fs_total)
  238. crit = self.range_dehumanize(crit, fs_total)
  239. returncode = self.value_wc_to_returncode(fs_used, warn, crit)
  240. output = volume + ': Used ' + self.value_to_human_binary(fs_used, 'B')
  241. output += ' (' + '%3.1f' % fs_pctused + '%)'+ ' out of ' + self.value_to_human_binary(fs_total, 'B')
  242. target = volume.replace('/vol/', '')[:-1]
  243. perfdata = []
  244. perfdata.append({'label':'navdu_' + target, 'value':fs_used, 'unit':'B', 'warn':warn, 'crit':crit, 'min':0})
  245. perfdata.append({'label':'navdt_' + target, 'value':fs_total, 'unit':'B'})
  246. perfdata.append({'label':'navsu_' + target, 'value':sn_used, 'unit':'B', 'min':0})
  247. perfdata.append({'label':'navst_' + target, 'value':sn_total, 'unit':'B'})
  248. return self.remember_check('vol_data', returncode, output, perfdata=perfdata, target=target)
  249. def check_vol_snap(self, volume, warn, crit):
  250. (idx, sn_idx) = self.common_vol_idx(volume)
  251. # fs_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], idx)) * 1024L
  252. # fs_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], idx)) * 1024L
  253. # fs_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], idx)) * 1024L
  254. sn_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], sn_idx)) * 1024L
  255. sn_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], sn_idx)) * 1024L
  256. # sn_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], sn_idx)) * 1024L
  257. sn_pctused = float(sn_used) / float(sn_total) * 100.0
  258. warn = self.range_dehumanize(warn, sn_total)
  259. crit = self.range_dehumanize(crit, sn_total)
  260. returncode = self.value_wc_to_returncode(sn_used, warn, crit)
  261. output = volume + '.snapshot: Used ' + self.value_to_human_binary(sn_used, 'B')
  262. output += ' (' + '%3.1f' % sn_pctused + '%)'+ ' out of ' + self.value_to_human_binary(sn_total, 'B')
  263. target = volume.replace('/vol/', '')[:-1]
  264. perfdata = []
  265. perfdata.append({'label':'navsu_' + target, 'value':sn_used, 'unit':'B', 'warn':warn, 'crit':crit, 'min':0})
  266. perfdata.append({'label':'navst_' + target, 'value':sn_total, 'unit':'B'})
  267. return self.remember_check('vol_snap', returncode, output, perfdata=perfdata, target=target)
  268. def check_vol_inode(self, volume, warn, crit):
  269. (idx, sn_idx) = self.common_vol_idx(volume)
  270. in_used = long(self.SNMPGET(self.OID['df_FS_INodeUsed'] + '.' + idx))
  271. in_free = long(self.SNMPGET(self.OID['df_FS_INodeFree'] + '.' + idx))
  272. in_total = in_used + in_free
  273. in_pctused = float(in_used) / float(in_total) * 100.0
  274. warn = self.range_dehumanize(warn, in_total)
  275. crit = self.range_dehumanize(crit, in_total)
  276. returncode = self.value_wc_to_returncode(in_used, warn, crit)
  277. output = volume + ': Used inodes ' + self.value_to_human_si(in_used)
  278. output += ' (' + '%3.1f' % in_pctused + '%)'+ ' out of ' + self.value_to_human_si(in_total)
  279. target = volume.replace('/vol/', '')[:-1]
  280. perfdata = []
  281. perfdata.append({'label':'naviu_' + target, 'value':in_used, 'unit':None, 'warn':warn, 'crit':crit, 'min':0})
  282. perfdata.append({'label':'navit_' + target, 'value':in_total, 'unit':None})
  283. return self.remember_check('vol_inode', returncode, output, perfdata=perfdata, target=target)
  284. def check_vol_files(self, volume, warn, crit):
  285. (idx, sn_idx) = self.common_vol_idx(volume)
  286. fi_avail = long(self.SNMPGET(self.OID['df_FS_MaxFilesAvail'] + '.' + idx))
  287. fi_used = long(self.SNMPGET(self.OID['df_FS_MaxFilesUsed'] + '.' + idx))
  288. fi_possible = long(self.SNMPGET(self.OID['df_FS_MaxFilesPossible'] + '.' + idx))
  289. fi_total = fi_used + fi_avail
  290. fi_pctused = float(fi_used) / float(fi_total) * 100.0
  291. warn = self.range_dehumanize(warn, fi_total)
  292. crit = self.range_dehumanize(crit, fi_total)
  293. returncode = self.value_wc_to_returncode(fi_used, warn, crit)
  294. output = volume + ': Used files ' + self.value_to_human_si(fi_used)
  295. output += ' (' + '%3.1f' % fi_pctused + '%)'+ ' out of ' + self.value_to_human_si(fi_total)
  296. output += ', may raised to ' + self.value_to_human_si(fi_possible)
  297. target = volume.replace('/vol/', '')[:-1]
  298. perfdata = []
  299. perfdata.append({'label':'navfu_' + target, 'value':fi_used, 'unit':None, 'warn':warn, 'crit':crit, 'min':0})
  300. perfdata.append({'label':'navft_' + target, 'value':fi_total, 'unit':None})
  301. return self.remember_check('vol_files', returncode, output, perfdata=perfdata, target=target)
  302. def main():
  303. plugin = CheckNAF(pluginname='check_naf', tagforstatusline='NAF', description=u'Monitoring NetApp™ FAS systems', version='0.9')
  304. plugin.add_cmdlineoption('', '--check', 'check', 'OBSOLETE - use new syntax!', default='')
  305. plugin.add_cmdlineoption('', '--target', 'target', 'OBSOLETE - use new syntax!', default='')
  306. plugin.add_cmdlineoption('-w', '', 'warn', 'OBSOLETE - use new syntax!', default='')
  307. plugin.add_cmdlineoption('-c', '', 'crit', 'OBSOLETE - use new syntax!', default='')
  308. plugin.parse_cmdlineoptions()
  309. plugin.prepare_snmp()
  310. if plugin.options.check or plugin.options.target:
  311. import sys
  312. arguments = plugin.options.check
  313. for s in [plugin.options.target, plugin.options.warn, plugin.options.crit]:
  314. arguments += ':' + s
  315. plugin.back2nagios(3, 'Obsolete syntax - please use new syntax: "%s %s"' % (sys.argv[0], arguments))
  316. checks = []
  317. for quad in plugin.args:
  318. quad = quad.split(':')
  319. quad = (quad + ['', '', ''])[:4] # Fix length to 4, fill with ''
  320. # Convert list of checks to list
  321. if ',' in quad[0]:
  322. quad[0] = quad[0].split(',')
  323. else:
  324. quad[0] = [quad[0],]
  325. # Convert list of targets to list
  326. if ',' in quad[1]:
  327. quad[1] = quad[1].split(',')
  328. else:
  329. quad[1] = [quad[1],]
  330. for target in quad[1]:
  331. for check in quad[0]:
  332. checks.append(tuple([check, target, quad[2], quad[3]]))
  333. if len(checks) == 0:
  334. checks = [('global','','','')]
  335. for quad in checks:
  336. (check, target, warn, crit) = tuple(quad)
  337. if check == 'global' or check == 'environment':
  338. result = plugin.check_global()
  339. elif check == 'cluster':
  340. result = plugin.check_cluster()
  341. elif check == 'cpu':
  342. result = plugin.check_cpu(warn=warn, crit=crit)
  343. elif check == 'disk':
  344. result = plugin.check_disk(target=target, warn=warn, crit=crit)
  345. elif check == 'extcache':
  346. result = plugin.check_extcache()
  347. elif check == 'extcache_info':
  348. result = plugin.check_extcache_info()
  349. elif check == 'nvram':
  350. result = plugin.check_nvram()
  351. elif check == 'version':
  352. result = plugin.check_version()
  353. elif check == 'vol_data':
  354. result = plugin.check_vol_data(volume=target, warn=warn, crit=crit)
  355. elif check == 'vol_snap':
  356. result = plugin.check_vol_snap(volume=target, warn=warn, crit=crit)
  357. elif check =='vol_inode':
  358. result = plugin.check_vol_inode(volume=target, warn=warn, crit=crit)
  359. elif check =='vol_files':
  360. result = plugin.check_vol_files(volume=target, warn=warn, crit=crit)
  361. else:
  362. result = plugin.remember_check(check, plugin.RETURNCODE['UNKNOWN'], 'Unknown check "' + check + '"!')
  363. # from pprint import pprint
  364. # pprint(plugin.dump_brain())
  365. plugin.brain2output()
  366. plugin.exit()
  367. if __name__ == '__main__':
  368. main()
  369. #vim: ts=4 sw=4 foldmethod=indent