check_naf.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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. 'Net_ifIndex': '.1.3.6.1.4.1.789.1.22.1.2.1.1',
  56. 'Net_ifDescr': '.1.3.6.1.4.1.789.1.22.1.2.1.2',
  57. 'Net_InBytes': ['.1.3.6.1.4.1.789.1.22.1.2.1.25', '.1.3.6.1.4.1.789.1.22.1.2.1.4', '.1.3.6.1.4.1.789.1.22.1.2.1.3',],
  58. 'Net_OutBytes': ['.1.3.6.1.4.1.789.1.22.1.2.1.31', '.1.3.6.1.4.1.789.1.22.1.2.1.16', '.1.3.6.1.4.1.789.1.22.1.2.1.15',],
  59. 'Net_InDiscards': ['.1.3.6.1.4.1.789.1.22.1.2.1.28', '.1.3.6.1.4.1.789.1.22.1.2.1.10', '.1.3.6.1.4.1.789.1.22.1.2.1.9',],
  60. 'Net_OutDiscards': ['.1.3.6.1.4.1.789.1.22.1.2.1.34', '.1.3.6.1.4.1.789.1.22.1.2.1.22', '.1.3.6.1.4.1.789.1.22.1.2.1.21',],
  61. 'Net_InErrors': ['.1.3.6.1.4.1.789.1.22.1.2.1.29', '.1.3.6.1.4.1.789.1.22.1.2.1.12', '.1.3.6.1.4.1.789.1.22.1.2.1.11',],
  62. 'Net_OutErrors': ['.1.3.6.1.4.1.789.1.22.1.2.1.35', '.1.3.6.1.4.1.789.1.22.1.2.1.24', '.1.3.6.1.4.1.789.1.22.1.2.1.23',],
  63. 'IO_DiskReadBy': ['.1.3.6.1.4.1.789.1.2.2.32.0', '.1.3.6.1.4.1.789.1.2.2.16.0', '.1.3.6.1.4.1.789.1.2.2.15.0',],
  64. 'IO_DiskWriteBy': ['.1.3.6.1.4.1.789.1.2.2.33.0', '.1.3.6.1.4.1.789.1.2.2.18.0', '.1.3.6.1.4.1.789.1.2.2.17.0',],
  65. 'IO_NetInBy': ['.1.3.6.1.4.1.789.1.2.2.30.0', '.1.3.6.1.4.1.789.1.2.2.12.0', '.1.3.6.1.4.1.789.1.2.2.11.0',],
  66. 'IO_NetOutBy': ['.1.3.6.1.4.1.789.1.2.2.31.0', '.1.3.6.1.4.1.789.1.2.2.14.0', '.1.3.6.1.4.1.789.1.2.2.13.0',],
  67. 'IO_TapeReadBy': ['.1.3.6.1.4.1.789.1.2.2.34.0', '.1.3.6.1.4.1.789.1.2.2.20.0', '.1.3.6.1.4.1.789.1.2.2.19.0',],
  68. 'IO_TapeWriteBy': ['.1.3.6.1.4.1.789.1.2.2.35.0', '.1.3.6.1.4.1.789.1.2.2.22.0', '.1.3.6.1.4.1.789.1.2.2.21.0',],
  69. 'IO_FCPReadBy': ['.1.3.6.1.4.1.789.1.17.20.0', '.1.3.6.1.4.1.789.1.17.3.0', '.1.3.6.1.4.1.789.1.17.4.0',],
  70. 'IO_FCPWriteBy': ['.1.3.6.1.4.1.789.1.17.21.0', '.1.3.6.1.4.1.789.1.17.5.0', '.1.3.6.1.4.1.789.1.17.6.0',],
  71. 'IO_iSCSIReadBy': ['.1.3.6.1.4.1.789.1.17.22.0', '.1.3.6.1.4.1.789.1.17.7.0', '.1.3.6.1.4.1.789.1.17.8.0',],
  72. 'IO_iSCSIWriteBy': ['.1.3.6.1.4.1.789.1.17.23.0', '.1.3.6.1.4.1.789.1.17.9.0', '.1.3.6.1.4.1.789.1.17.10.0',],
  73. 'NVRAM_Status': '.1.3.6.1.4.1.789.1.2.5.1.0',
  74. 'OPs_NFS': ['.1.3.6.1.4.1.789.1.2.2.27.0', '.1.3.6.1.4.1.789.1.2.2.6.0', '.1.3.6.1.4.1.789.1.2.2.5.0',],
  75. 'OPs_CIFS': ['.1.3.6.1.4.1.789.1.2.2.28.0', '.1.3.6.1.4.1.789.1.2.2.8.0', '.1.3.6.1.4.1.789.1.2.2.7.0',],
  76. 'OPs_HTTP': ['.1.3.6.1.4.1.789.1.2.2.29.0', '.1.3.6.1.4.1.789.1.2.2.10.0', '.1.3.6.1.4.1.789.1.2.2.9.0',],
  77. 'OPs_FCP': ['.1.3.6.1.4.1.789.1.17.25.0', '.1.3.6.1.4.1.789.1.17.14.0', '.1.3.6.1.4.1.789.1.17.13.0',],
  78. 'OPs_iSCSI': ['.1.3.6.1.4.1.789.1.17.24.0', '.1.3.6.1.4.1.789.1.17.12.0', '.1.3.6.1.4.1.789.1.17.11.0',],
  79. 'Model': '.1.3.6.1.4.1.789.1.1.5.0',
  80. 'ONTAP_Version': '.1.3.6.1.4.1.789.1.1.2.0',
  81. 'df_FS_Index': '.1.3.6.1.4.1.789.1.5.4.1.1',
  82. 'df_FS_Name': '.1.3.6.1.4.1.789.1.5.4.1.2',
  83. 'df_FS_Mounted_On': '.1.3.6.1.4.1.789.1.5.4.1.10',
  84. 'df_FS_Status': '.1.3.6.1.4.1.789.1.5.4.1.20',
  85. 'df_FS_Type': '.1.3.6.1.4.1.789.1.5.4.1.23',
  86. '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',],
  87. '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',],
  88. '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',],
  89. 'df_FS_INodeUsed': '.1.3.6.1.4.1.789.1.5.4.1.7',
  90. 'df_FS_INodeFree': '.1.3.6.1.4.1.789.1.5.4.1.8',
  91. 'df_FS_MaxFilesAvail': '.1.3.6.1.4.1.789.1.5.4.1.11',
  92. 'df_FS_MaxFilesUsed': '.1.3.6.1.4.1.789.1.5.4.1.12',
  93. 'df_FS_MaxFilesPossible': '.1.3.6.1.4.1.789.1.5.4.1.13',
  94. }
  95. OWC = {
  96. 'Cluster_InterconnectStatus': ( (4,), (3,), (1,2,), ),
  97. 'Cluster_Settings': ( (2,), (1,3,4,), (5,), ),
  98. 'Cluster_State': ( (2,4,), (), (1,3,), ),
  99. 'Global_Status': ( (3,), (4,), (5,6), ),
  100. 'NVRAM_Status': ( (1,9), (2,5,8), (3,4,6), ),
  101. }
  102. Status2String = {
  103. 'Cluster_CannotTakeOverCause': { '1' : 'ok', '2' : 'unknownReason', '3' : 'disabledByOperator', '4' : 'interconnectOffline', '5' : 'disabledByPartner', '6' : 'takeoverFailed', },
  104. 'Cluster_InterconnectStatus': { '1' : 'notPresent', '2' : 'down', '3' : 'partialFailure', '4' : 'up', },
  105. 'Cluster_Settings': { '1' : 'notConfigured', '2' : 'enabled', '3' : 'disabled', '4' : 'takeoverByPartnerDisabled', '5' : 'thisNodeDead', },
  106. 'Cluster_State': { '1' : 'dead', '2' : 'canTakeover', '3' : 'cannotTakeover', '4' : 'takeover', },
  107. 'CPU_Arch' : { '1' : 'x86', '2' : 'alpha', '3' : 'mips', '4' : 'sparc', '5' : 'amd64', },
  108. 'NVRAM_Status' : { '1' : 'ok', '2' : 'partiallyDischarged', '3' : 'fullyDischarged', '4' : 'notPresent', '5' : 'nearEndOfLife', '6' : 'atEndOfLife', '7' : 'unknown', '8' : 'overCharged', '9' : 'fullyCharged', },
  109. 'df_FS_Status' : { '1' : 'unmounted', '2' : 'mounted', '3' : 'frozen', '4' : 'destroying', '5' : 'creating', '6' : 'mounting', '7' : 'unmounting', '8' : 'nofsinfo', '9' : 'replaying', '10': 'replayed', },
  110. 'df_FS_Type' : { '1' : 'traditionalVolume', '2' : 'flexibleVolume', '3' : 'aggregate', },
  111. }
  112. def map_status_to_returncode(self, value, mapping):
  113. for returncode in xrange(0,3):
  114. if value in mapping[returncode]:
  115. return returncode
  116. return 3
  117. def check_cpu(self, warn='', crit=''):
  118. cpu_arch = self.SNMPGET(self.OID['CPU_Arch'])
  119. cpu_timebusy = int(self.SNMPGET(self.OID['CPU_Time_Busy']))
  120. # cputimeidle = int(self.SNMPGET(self.OID['CPU_Time_Idle']))
  121. cpu_cs = self.SNMPGET(self.OID['CPU_Context_Switches'])
  122. if '%' in warn:
  123. warn = warn[:-1]
  124. if '%' in crit:
  125. crit = crit[:-1]
  126. returncode = self.value_wc_to_returncode(cpu_timebusy, warn, crit)
  127. output = 'CPU ' + str(cpu_timebusy) + '% busy, CPU architecture: ' + self.Status2String['CPU_Arch'].get(cpu_arch)
  128. perfdata = []
  129. pd = {'label':'nacpu', 'value':cpu_timebusy, 'unit':'%', 'min':0, 'max':100}
  130. if warn:
  131. pd['warn'] = warn
  132. if crit:
  133. pd['crit'] = crit
  134. perfdata.append(pd)
  135. perfdata.append({'label':'nacs', 'value':cpu_cs, 'unit':'c'})
  136. return self.remember_check('cpu', returncode, output, perfdata=perfdata)
  137. def check_cluster(self):
  138. cl_settings = int(self.SNMPGET(self.OID['Cluster_Settings']))
  139. if cl_settings == 1: # notConfigured
  140. return self.remember_check('cluster', self.RETURNCODE['WARNING'], 'No cluster configured!')
  141. cl_state = int(self.SNMPGET(self.OID['Cluster_State']))
  142. cl_interconnectstatus = int(self.SNMPGET(self.OID['Cluster_InterconnectStatus']))
  143. returncode = []
  144. returncode.append(self.map_status_to_returncode(cl_settings, self.OWC['Cluster_Settings']))
  145. returncode.append(self.map_status_to_returncode(cl_state, self.OWC['Cluster_State']))
  146. returncode.append(self.map_status_to_returncode(cl_interconnectstatus, self.OWC['Cluster_InterconnectStatus']))
  147. returncode = max(returncode)
  148. output = 'Settings: ' + self.Status2String['Cluster_Settings'][str(cl_settings)] + ', '
  149. output += 'state: ' + self.Status2String['Cluster_State'][str(cl_state)] + ', '
  150. output += 'interconnect state: ' + self.Status2String['Cluster_InterconnectStatus'][str(cl_interconnectstatus)]
  151. if cl_state == 4: # cannotTakeover
  152. cl_cannottakeovercause = self.SNMPGET(self.OID['Cluster_CannotTakeOverCause'])
  153. output = 'Cannot takeover, reason: ' + self.Status2String['Cluster_CannotTakeOverCause'][cl_cannottakeovercause] + '! ' + output
  154. return self.remember_check('cluster', returncode, output)
  155. def check_disk(self, target='failed', warn='', crit=''):
  156. di_total = int(self.SNMPGET(self.OID['Disks_Total']))
  157. di_active = int(self.SNMPGET(self.OID['Disks_Active']))
  158. di_reconstructing = int(self.SNMPGET(self.OID['Disks_Reconstructing']))
  159. di_reconstparity = int(self.SNMPGET(self.OID['Disks_ReconstParity']))
  160. # di_scrubbing = int(self.SNMPGET(self.OID['Disks_Scrubbing']))
  161. di_failed = int(self.SNMPGET(self.OID['Disks_Failed']))
  162. di_spare = int(self.SNMPGET(self.OID['Disks_Spare']))
  163. # di_zerodisks = int(self.SNMPGET(self.OID['Disks_ZeroDisks']))
  164. di_reconstr = di_reconstructing + di_reconstparity
  165. if target == 'spare':
  166. returncode = self.value_wc_to_returncode(di_spare, warn, crit)
  167. output = str(di_spare) + ' spare disk'
  168. if di_spare > 1:
  169. output += 's'
  170. else:
  171. target = 'failed' # Set to defined value
  172. returncode = self.value_wc_to_returncode(di_failed, warn, crit)
  173. if returncode == 0:
  174. output = 'No failed disks'
  175. else:
  176. output = self.SNMPGET(self.OID['Disks_Failed_Descr'])
  177. perfdata = []
  178. perfdata.append({'label':'nadisk_total', 'value':di_total, 'unit':'', 'min':0})
  179. perfdata.append({'label':'nadisk_active', 'value':di_active, 'unit':'', 'min':0})
  180. pd = {'label':'nadisk_spare', 'value':di_spare, 'unit':'', 'min':0}
  181. if warn and target=='spare':
  182. pd['warn'] = warn
  183. if crit and target=='spare':
  184. pd['crit'] = crit
  185. perfdata.append(pd)
  186. pd = {'label':'nadisk_failed', 'value':di_failed, 'unit':'', 'min':0}
  187. if warn and target=='failed':
  188. pd['warn'] = warn
  189. if crit and target=='failed':
  190. pd['crit'] = crit
  191. perfdata.append(pd)
  192. return self.remember_check('disk', returncode, output, perfdata=perfdata, target=target)
  193. def check_extcache(self):
  194. if self.options.snmpversion in [1, '1']:
  195. return self.remember_check('extcache', self.RETURNCODE['UNKNOWN'], 'Need SNMP v2c/v3 for "extcache" check!',)
  196. ec_size = long(self.SNMPGET(self.OID['ExtCache_Size']))
  197. ec_usedsize = long(self.SNMPGET(self.OID['ExtCache_Usedsize']))
  198. ec_hits = long(self.SNMPGET(self.OID['ExtCache_Hits']))
  199. # ec_meta = long(self.SNMPGET(self.OID['ExtCache_MetaData']))
  200. ec_miss = long(self.SNMPGET(self.OID['ExtCache_Misses']))
  201. ec_evict = long(self.SNMPGET(self.OID['ExtCache_Evicts']))
  202. ec_inval = long(self.SNMPGET(self.OID['ExtCache_Invalidates']))
  203. ec_insert = long(self.SNMPGET(self.OID['ExtCache_Inserts']))
  204. ec_usage = float(ec_usedsize) / float(ec_size) * 100.0
  205. ec_hitpct = float(ec_hits) / float(ec_hits + ec_miss) * 100.0
  206. ec_size_human = self.value_to_human_binary(ec_size, unit='B')
  207. output = 'Cache size %s, cache usage %5.2f%%, total hits %5.2f%% ' % (ec_size_human, ec_usage, ec_hitpct)
  208. returncode = self.RETURNCODE['OK']
  209. perfdata = []
  210. perfdata.append({'label':'nacache_usage', 'value':float('%5.2f' % ec_usage), 'unit':'%'})
  211. perfdata.append({'label':'nacache_hits', 'value':ec_hits, 'unit':'c'})
  212. perfdata.append({'label':'nacache_miss', 'value':ec_miss, 'unit':'c'})
  213. perfdata.append({'label':'nacache_evict', 'value':ec_evict, 'unit':'c'})
  214. perfdata.append({'label':'nacache_inval', 'value':ec_inval, 'unit':'c'})
  215. perfdata.append({'label':'nacache_insert', 'value':ec_insert, 'unit':'c'})
  216. return self.remember_check('extcache', returncode, output, perfdata=perfdata)
  217. def check_extcache_info(self):
  218. ec_type = self.SNMPGET(self.OID['ExtCache_Type'])
  219. ec_subtype = self.SNMPGET(self.OID['ExtCache_SubType'])
  220. ec_size = long(self.SNMPGET(self.OID['ExtCache_Size']))
  221. ec_options = self.SNMPGET(self.OID['ExtCache_Options'])
  222. ec_size_human = self.value_to_human_binary(ec_size, unit='B')
  223. output = 'Cache type: "' + ec_type + '/' + ec_subtype + '", size: ' + ec_size_human + ', options: "' + ec_options + '"'
  224. returncode = 0
  225. return self.remember_check('extcache_info', returncode, output)
  226. def check_global(self):
  227. model = self.SNMPGET(self.OID['Model'])
  228. globalstatus = int(self.SNMPGET(self.OID['Global_Status']))
  229. globalstatusmsg = self.SNMPGET(self.OID['Global_Status_Message'])[:255]
  230. returncode = self.map_status_to_returncode(globalstatus, self.OWC['Global_Status'])
  231. output = model + ': ' + globalstatusmsg
  232. return self.remember_check('global', returncode, output)
  233. def check_ifstat(self, nic):
  234. idx = self.find_in_table(self.OID['Net_ifIndex'], self.OID['Net_ifDescr'] , nic)
  235. if idx == None:
  236. return self.remember_check('ifstat:'+nic, self.RETURNCODE['UNKNOWN'], 'NIC "' + nic + '" not found!')
  237. n_bytes_in = self.SNMPGET(self.OID['Net_InBytes'], idx)
  238. n_bytes_out = self.SNMPGET(self.OID['Net_OutBytes'], idx)
  239. n_discards_in = self.SNMPGET(self.OID['Net_InDiscards'], idx)
  240. n_discards_out = self.SNMPGET(self.OID['Net_OutDiscards'], idx)
  241. n_errors_in = self.SNMPGET(self.OID['Net_InErrors'], idx)
  242. n_errors_out = self.SNMPGET(self.OID['Net_OutErrors'], idx)
  243. returncode = self.RETURNCODE['OK']
  244. output = 'Network statistics for %s' % nic
  245. perfdata = []
  246. perfdata.append({'label':'naifbyin_'+nic, 'value':n_bytes_in, 'unit':'c'})
  247. perfdata.append({'label':'naifbyout_'+nic, 'value':n_bytes_out, 'unit':'c'})
  248. perfdata.append({'label':'naifdiscin_'+nic, 'value':n_discards_in, 'unit':'c'})
  249. perfdata.append({'label':'naifdiscout_'+nic, 'value':n_discards_out, 'unit':'c'})
  250. perfdata.append({'label':'naiferrin_'+nic, 'value':n_errors_in, 'unit':'c'})
  251. perfdata.append({'label':'naiferrout_'+nic, 'value':n_errors_out, 'unit':'c'})
  252. return self.remember_check('ifstat:'+nic, returncode, output, perfdata=perfdata)
  253. def check_io(self):
  254. disk_read = self.SNMPGET(self.OID['IO_DiskReadBy'])
  255. disk_write = self.SNMPGET(self.OID['IO_DiskWriteBy'])
  256. net_in = self.SNMPGET(self.OID['IO_NetInBy'])
  257. net_out = self.SNMPGET(self.OID['IO_NetOutBy'])
  258. tape_read = self.SNMPGET(self.OID['IO_TapeReadBy'])
  259. tape_write = self.SNMPGET(self.OID['IO_TapeWriteBy'])
  260. fcp_read = self.SNMPGET(self.OID['IO_FCPReadBy'])
  261. fcp_write = self.SNMPGET(self.OID['IO_FCPWriteBy'])
  262. iscsi_read = self.SNMPGET(self.OID['IO_iSCSIReadBy'])
  263. iscsi_write = self.SNMPGET(self.OID['IO_iSCSIWriteBy'])
  264. output = 'I/O statistics'
  265. returncode = self.RETURNCODE['OK']
  266. perfdata = []
  267. perfdata.append({'label':'naio_netin', 'value':net_in, 'unit':'c'})
  268. perfdata.append({'label':'naio_netout', 'value':net_out, 'unit':'c'})
  269. perfdata.append({'label':'naio_diskread', 'value':disk_read, 'unit':'c'})
  270. perfdata.append({'label':'naio_diskwrite', 'value':disk_write, 'unit':'c'})
  271. perfdata.append({'label':'naio_taperead', 'value':tape_read, 'unit':'c'})
  272. perfdata.append({'label':'naio_tapewrite', 'value':tape_write, 'unit':'c'})
  273. perfdata.append({'label':'naio_fcpread', 'value':fcp_read, 'unit':'c'})
  274. perfdata.append({'label':'naio_fcpwrite', 'value':fcp_write, 'unit':'c'})
  275. perfdata.append({'label':'naio_iscsiread', 'value':iscsi_read, 'unit':'c'})
  276. perfdata.append({'label':'naio_iscsiwrite', 'value':iscsi_write, 'unit':'c'})
  277. return self.remember_check('io', returncode, output, perfdata=perfdata)
  278. def check_nvram(self):
  279. nvramstatus = int(self.SNMPGET(self.OID['NVRAM_Status']))
  280. returncode = self.map_status_to_returncode(nvramstatus, self.OWC['NVRAM_Status'])
  281. output = 'NVRAM battery status is "' + self.Status2String['NVRAM_Status'].get(str(nvramstatus)) + '"'
  282. return self.remember_check('nvram', returncode, output)
  283. def check_ops(self):
  284. ops_nfs = self.SNMPGET(self.OID['OPs_NFS'])
  285. ops_cifs = self.SNMPGET(self.OID['OPs_CIFS'])
  286. ops_http = self.SNMPGET(self.OID['OPs_HTTP'])
  287. ops_fcp = self.SNMPGET(self.OID['OPs_FCP'])
  288. ops_iscsi = self.SNMPGET(self.OID['OPs_iSCSI'])
  289. output = 'Total ops statistics'
  290. returncode = self.RETURNCODE['OK']
  291. perfdata = []
  292. perfdata.append({'label':'naops_nfs', 'value':ops_nfs, 'unit':'c'})
  293. perfdata.append({'label':'naops_cifs', 'value':ops_cifs, 'unit':'c'})
  294. perfdata.append({'label':'naops_http', 'value':ops_http, 'unit':'c'})
  295. perfdata.append({'label':'naops_fcp', 'value':ops_fcp, 'unit':'c'})
  296. perfdata.append({'label':'naops_iscsi', 'value':ops_iscsi, 'unit':'c'})
  297. return self.remember_check('ops', returncode, output, perfdata=perfdata)
  298. def check_version(self):
  299. model = self.SNMPGET(self.OID['Model'])
  300. ontapversion = self.SNMPGET(self.OID['ONTAP_Version'])
  301. return self.remember_check('version', 0, model + ': ' + ontapversion)
  302. def common_vol_idx(self, volume):
  303. if volume.endswith('.snapshot'):
  304. return None
  305. idx = self.find_in_table(self.OID['df_FS_Index'], self.OID['df_FS_Name'] , volume)
  306. if idx != None:
  307. sn_idx = int(idx) + 1
  308. else:
  309. sn_idx = None
  310. return (idx, sn_idx)
  311. def check_vol_data(self, volume, warn, crit):
  312. (idx, sn_idx) = self.common_vol_idx(volume)
  313. if idx == None:
  314. return self.remember_check('vol_data', self.RETURNCODE['UNKNOWN'], '"' + volume + '" not found!')
  315. fs_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], idx)) * 1024L
  316. fs_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], idx)) * 1024L
  317. # fs_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], idx)) * 1024L
  318. sn_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], sn_idx)) * 1024L
  319. sn_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], sn_idx)) * 1024L
  320. # sn_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], sn_idx)) * 1024L
  321. mountedon = self.SNMPGET(self.OID['df_FS_Mounted_On'] + "." + idx)
  322. status = self.Status2String['df_FS_Status'].get(self.SNMPGET(self.OID['df_FS_Status'] + "." + idx))
  323. fstype = self.Status2String['df_FS_Type'].get(self.SNMPGET(self.OID['df_FS_Type'] + "." + idx))
  324. fs_pctused = float(fs_used) / float(fs_total) * 100.0
  325. warn = self.range_dehumanize(warn, fs_total)
  326. crit = self.range_dehumanize(crit, fs_total)
  327. returncode = self.value_wc_to_returncode(fs_used, warn, crit)
  328. output = volume + ': Used ' + self.value_to_human_binary(fs_used, 'B')
  329. output += ' (' + '%3.1f' % fs_pctused + '%)'+ ' out of ' + self.value_to_human_binary(fs_total, 'B')
  330. target = volume.replace('/vol/', '')[:-1]
  331. perfdata = []
  332. perfdata.append({'label':'navdu_' + target, 'value':fs_used, 'unit':'B', 'warn':warn, 'crit':crit, 'min':0})
  333. perfdata.append({'label':'navdt_' + target, 'value':fs_total, 'unit':'B'})
  334. perfdata.append({'label':'navsu_' + target, 'value':sn_used, 'unit':'B', 'min':0})
  335. perfdata.append({'label':'navst_' + target, 'value':sn_total, 'unit':'B'})
  336. return self.remember_check('vol_data', returncode, output, perfdata=perfdata, target=target)
  337. def check_vol_snap(self, volume, warn, crit):
  338. (idx, sn_idx) = self.common_vol_idx(volume)
  339. if idx == None:
  340. return self.remember_check('vol_snap', self.RETURNCODE['UNKNOWN'], '"' + volume + '" not found!')
  341. # fs_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], idx)) * 1024L
  342. # fs_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], idx)) * 1024L
  343. # fs_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], idx)) * 1024L
  344. sn_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], sn_idx)) * 1024L
  345. sn_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], sn_idx)) * 1024L
  346. # sn_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], sn_idx)) * 1024L
  347. sn_pctused = float(sn_used) / float(sn_total) * 100.0
  348. warn = self.range_dehumanize(warn, sn_total)
  349. crit = self.range_dehumanize(crit, sn_total)
  350. returncode = self.value_wc_to_returncode(sn_used, warn, crit)
  351. output = volume + '.snapshot: Used ' + self.value_to_human_binary(sn_used, 'B')
  352. output += ' (' + '%3.1f' % sn_pctused + '%)'+ ' out of ' + self.value_to_human_binary(sn_total, 'B')
  353. target = volume.replace('/vol/', '')[:-1]
  354. perfdata = []
  355. perfdata.append({'label':'navsu_' + target, 'value':sn_used, 'unit':'B', 'warn':warn, 'crit':crit, 'min':0})
  356. perfdata.append({'label':'navst_' + target, 'value':sn_total, 'unit':'B'})
  357. return self.remember_check('vol_snap', returncode, output, perfdata=perfdata, target=target)
  358. def check_vol_inode(self, volume, warn, crit):
  359. (idx, sn_idx) = self.common_vol_idx(volume)
  360. if idx == None:
  361. return self.remember_check('vol_inode', self.RETURNCODE['UNKNOWN'], '"' + volume + '" not found!')
  362. in_used = long(self.SNMPGET(self.OID['df_FS_INodeUsed'] + '.' + idx))
  363. in_free = long(self.SNMPGET(self.OID['df_FS_INodeFree'] + '.' + idx))
  364. in_total = in_used + in_free
  365. in_pctused = float(in_used) / float(in_total) * 100.0
  366. warn = self.range_dehumanize(warn, in_total)
  367. crit = self.range_dehumanize(crit, in_total)
  368. returncode = self.value_wc_to_returncode(in_used, warn, crit)
  369. output = volume + ': Used inodes ' + self.value_to_human_si(in_used)
  370. output += ' (' + '%3.1f' % in_pctused + '%)'+ ' out of ' + self.value_to_human_si(in_total)
  371. target = volume.replace('/vol/', '')[:-1]
  372. perfdata = []
  373. perfdata.append({'label':'naviu_' + target, 'value':in_used, 'unit':None, 'warn':warn, 'crit':crit, 'min':0})
  374. perfdata.append({'label':'navit_' + target, 'value':in_total, 'unit':None})
  375. return self.remember_check('vol_inode', returncode, output, perfdata=perfdata, target=target)
  376. def check_vol_files(self, volume, warn, crit):
  377. (idx, sn_idx) = self.common_vol_idx(volume)
  378. if idx == None:
  379. return self.remember_check('vol_files', self.RETURNCODE['UNKNOWN'], '"' + volume + '" not found!')
  380. fi_avail = long(self.SNMPGET(self.OID['df_FS_MaxFilesAvail'] + '.' + idx))
  381. fi_used = long(self.SNMPGET(self.OID['df_FS_MaxFilesUsed'] + '.' + idx))
  382. fi_possible = long(self.SNMPGET(self.OID['df_FS_MaxFilesPossible'] + '.' + idx))
  383. fi_total = fi_used + fi_avail
  384. fi_pctused = float(fi_used) / float(fi_total) * 100.0
  385. warn = self.range_dehumanize(warn, fi_total)
  386. crit = self.range_dehumanize(crit, fi_total)
  387. returncode = self.value_wc_to_returncode(fi_used, warn, crit)
  388. output = volume + ': Used files ' + self.value_to_human_si(fi_used)
  389. output += ' (' + '%3.1f' % fi_pctused + '%)'+ ' out of ' + self.value_to_human_si(fi_total)
  390. output += ', may raised to ' + self.value_to_human_si(fi_possible)
  391. target = volume.replace('/vol/', '')[:-1]
  392. perfdata = []
  393. perfdata.append({'label':'navfu_' + target, 'value':fi_used, 'unit':None, 'warn':warn, 'crit':crit, 'min':0})
  394. perfdata.append({'label':'navft_' + target, 'value':fi_total, 'unit':None})
  395. return self.remember_check('vol_files', returncode, output, perfdata=perfdata, target=target)
  396. def main():
  397. plugin = CheckNAF(pluginname='check_naf', tagforstatusline='NAF', description=u'Monitoring NetApp™ FAS systems', version='0.9')
  398. plugin.add_cmdlineoption('', '--separator', 'separator', 'Separator for check/target/warn/crit', metavar=',', default=',')
  399. plugin.add_cmdlineoption('', '--subseparator', 'subseparator', 'Separator for multiple checks or targets', metavar='+', default='+')
  400. plugin.add_cmdlineoption('', '--check', 'check', 'OBSOLETE - use new syntax!', default='')
  401. plugin.add_cmdlineoption('', '--target', 'target', 'OBSOLETE - use new syntax!', default='')
  402. plugin.add_cmdlineoption('-w', '', 'warn', 'OBSOLETE - use new syntax!', default='')
  403. plugin.add_cmdlineoption('-c', '', 'crit', 'OBSOLETE - use new syntax!', default='')
  404. plugin.parse_cmdlineoptions()
  405. plugin.prepare_snmp()
  406. if plugin.options.check or plugin.options.target:
  407. import sys
  408. arguments = plugin.options.check
  409. for s in [plugin.options.target, plugin.options.warn, plugin.options.crit]:
  410. arguments += plugin.options.separator + s
  411. plugin.back2nagios(3, 'Obsolete syntax - please use new syntax: "%s %s"' % (sys.argv[0], arguments))
  412. checks = []
  413. for quad in plugin.args:
  414. quad = quad.split(plugin.options.separator)
  415. quad = (quad + ['', '', ''])[:4] # Fix length to 4, fill with ''
  416. # Convert list of checks to list
  417. if plugin.options.subseparator in quad[0]:
  418. quad[0] = quad[0].split(plugin.options.subseparator)
  419. else:
  420. quad[0] = [quad[0],]
  421. # Convert list of targets to list
  422. if plugin.options.subseparator in quad[1]:
  423. quad[1] = quad[1].split(plugin.options.subseparator)
  424. else:
  425. quad[1] = [quad[1],]
  426. for target in quad[1]:
  427. for check in quad[0]:
  428. checks.append(tuple([check, target, quad[2], quad[3]]))
  429. if len(checks) == 0:
  430. checks = [('global','','','')]
  431. for quad in checks:
  432. (check, target, warn, crit) = tuple(quad)
  433. if check == 'global' or check == 'environment':
  434. result = plugin.check_global()
  435. elif check == 'cluster':
  436. result = plugin.check_cluster()
  437. elif check == 'cpu':
  438. result = plugin.check_cpu(warn=warn, crit=crit)
  439. elif check == 'disk':
  440. result = plugin.check_disk(target=target, warn=warn, crit=crit)
  441. elif check == 'extcache':
  442. result = plugin.check_extcache()
  443. elif check == 'extcache_info':
  444. result = plugin.check_extcache_info()
  445. elif check == 'ifstat':
  446. result = plugin.check_ifstat(target)
  447. elif check == 'io':
  448. result = plugin.check_io()
  449. elif check == 'nvram':
  450. result = plugin.check_nvram()
  451. elif check == 'ops':
  452. result = plugin.check_ops()
  453. elif check == 'version':
  454. result = plugin.check_version()
  455. elif check == 'vol_data':
  456. result = plugin.check_vol_data(volume=target, warn=warn, crit=crit)
  457. elif check == 'vol_snap':
  458. result = plugin.check_vol_snap(volume=target, warn=warn, crit=crit)
  459. elif check =='vol_inode':
  460. result = plugin.check_vol_inode(volume=target, warn=warn, crit=crit)
  461. elif check =='vol_files':
  462. result = plugin.check_vol_files(volume=target, warn=warn, crit=crit)
  463. else:
  464. result = plugin.remember_check(check, plugin.RETURNCODE['UNKNOWN'], 'Unknown check "' + check + '"!')
  465. # from pprint import pprint
  466. # pprint(plugin.dump_brain())
  467. plugin.brain2output()
  468. plugin.exit()
  469. if __name__ == '__main__':
  470. main()
  471. #vim: ts=4 sw=4 foldmethod=indent