check_naf.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. 'CPU_Arch': '.1.3.6.1.4.1.789.1.1.11.0',
  26. 'CPU_Time_Busy': '.1.3.6.1.4.1.789.1.2.1.3.0',
  27. 'CPU_Time_Idle': '.1.3.6.1.4.1.789.1.2.1.5.0',
  28. 'CPU_Context_Switches': '.1.3.6.1.4.1.789.1.2.1.8.0',
  29. 'Disks_Total': '.1.3.6.1.4.1.789.1.6.4.1.0',
  30. 'Disks_Active': '.1.3.6.1.4.1.789.1.6.4.2.0',
  31. 'Disks_Reconstructing': '.1.3.6.1.4.1.789.1.6.4.3.0',
  32. 'Disks_ReconstParity': '.1.3.6.1.4.1.789.1.6.4.4.0',
  33. 'Disks_Scrubbing': '.1.3.6.1.4.1.789.1.6.4.6.0',
  34. 'Disks_Failed': '.1.3.6.1.4.1.789.1.6.4.7.0',
  35. 'Disks_Spare': '.1.3.6.1.4.1.789.1.6.4.8.0',
  36. 'Disks_ZeroDisks': '.1.3.6.1.4.1.789.1.6.4.9.0',
  37. 'Disks_Failed_Descr': '.1.3.6.1.4.1.789.1.6.4.10.0',
  38. 'Global_Status': '.1.3.6.1.4.1.789.1.2.2.4.0',
  39. 'Global_Status_Message': '.1.3.6.1.4.1.789.1.2.2.25.0',
  40. 'NVRAM_Status': '.1.3.6.1.4.1.789.1.2.5.1.0',
  41. 'Model': '.1.3.6.1.4.1.789.1.1.5.0',
  42. 'ONTAP_Version': '.1.3.6.1.4.1.789.1.1.2.0',
  43. 'df_FS_Index': '.1.3.6.1.4.1.789.1.5.4.1.1',
  44. 'df_FS_Name': '.1.3.6.1.4.1.789.1.5.4.1.2',
  45. 'df_FS_Mounted_On': '.1.3.6.1.4.1.789.1.5.4.1.10',
  46. 'df_FS_Status': '.1.3.6.1.4.1.789.1.5.4.1.20',
  47. 'df_FS_Type': '.1.3.6.1.4.1.789.1.5.4.1.23',
  48. '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',],
  49. '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',],
  50. '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',],
  51. 'df_FS_INodeUsed': '.1.3.6.1.4.1.789.1.5.4.1.7',
  52. 'df_FS_INodeFree': '.1.3.6.1.4.1.789.1.5.4.1.8',
  53. 'df_FS_MaxFilesAvail': '.1.3.6.1.4.1.789.1.5.4.1.11',
  54. 'df_FS_MaxFilesUsed': '.1.3.6.1.4.1.789.1.5.4.1.12',
  55. 'df_FS_MaxFilesPossible': '.1.3.6.1.4.1.789.1.5.4.1.13',
  56. }
  57. OWC = {
  58. 'Global_Status': ( (3,), (4,), (5,6), ),
  59. 'NVRAM_Status': ( (1,9), (2,5,8), (3,4,6), ),
  60. }
  61. Status2String = {
  62. 'CPU_Arch' : { '1' : 'x86', '2' : 'alpha', '3' : 'mips', '4' : 'sparc', '5' : 'amd64', },
  63. 'NVRAM_Status' : { '1' : 'ok', '2' : 'partiallyDischarged', '3' : 'fullyDischarged', '4' : 'notPresent', '5' : 'nearEndOfLife', '6' : 'atEndOfLife', '7' : 'unknown', '8' : 'overCharged', '9' : 'fullyCharged', },
  64. 'df_FS_Status' : { '1' : 'unmounted', '2' : 'mounted', '3' : 'frozen', '4' : 'destroying', '5' : 'creating', '6' : 'mounting', '7' : 'unmounting', '8' : 'nofsinfo', '9' : 'replaying', '10': 'replayed', },
  65. 'df_FS_Type' : { '1' : 'traditionalVolume', '2' : 'flexibleVolume', '3' : 'aggregate', },
  66. }
  67. def map_status_to_returncode(self, value, mapping):
  68. for returncode in xrange(0,3):
  69. if value in mapping[returncode]:
  70. return returncode
  71. return 3
  72. def check_cpu(self, warn='', crit=''):
  73. cpu_arch = self.SNMPGET(self.OID['CPU_Arch'])
  74. cpu_timebusy = int(self.SNMPGET(self.OID['CPU_Time_Busy']))
  75. # cputimeidle = int(self.SNMPGET(self.OID['CPU_Time_Idle']))
  76. cpu_cs = self.SNMPGET(self.OID['CPU_Context_Switches'])
  77. returncode = self.value_wc_to_returncode(cpu_timebusy, warn, crit)
  78. output = 'CPU ' + str(cpu_timebusy) + '% busy, CPU architecture: ' + self.Status2String['CPU_Arch'].get(cpu_arch)
  79. perfdata = []
  80. pd = {'label':'nacpu', 'value':cpu_timebusy, 'unit':'%', 'min':0, 'max':100}
  81. if warn:
  82. pd['warn'] = warn
  83. if crit:
  84. pd['crit'] = crit
  85. perfdata.append(pd)
  86. perfdata.append({'label':'nacs', 'value':cpu_cs, 'unit':'c'})
  87. return self.remember_check('cpu', returncode, output, perfdata=perfdata)
  88. def check_disk(self, target='failed', warn='', crit=''):
  89. di_total = int(self.SNMPGET(self.OID['Disks_Total']))
  90. di_active = int(self.SNMPGET(self.OID['Disks_Active']))
  91. di_reconstructing = int(self.SNMPGET(self.OID['Disks_Reconstructing']))
  92. di_reconstparity = int(self.SNMPGET(self.OID['Disks_ReconstParity']))
  93. # di_scrubbing = int(self.SNMPGET(self.OID['Disks_Scrubbing']))
  94. di_failed = int(self.SNMPGET(self.OID['Disks_Failed']))
  95. di_spare = int(self.SNMPGET(self.OID['Disks_Spare']))
  96. # di_zerodisks = int(self.SNMPGET(self.OID['Disks_ZeroDisks']))
  97. di_reconstr = di_reconstructing + di_reconstparity
  98. if target == 'spare':
  99. returncode = self.value_wc_to_returncode(di_spare, warn, crit)
  100. output = str(di_spare) + ' spare disk'
  101. if di_spare > 1:
  102. output += 's'
  103. else:
  104. target = 'failed' # Set to defined value
  105. returncode = self.value_wc_to_returncode(di_failed, warn, crit)
  106. if returncode == 0:
  107. output = 'No failed disks'
  108. else:
  109. output = self.SNMPGET(self.OID['Disks_Failed_Descr'])
  110. perfdata = []
  111. perfdata.append({'label':'nadisk_total', 'value':di_total, 'unit':'', 'min':0})
  112. perfdata.append({'label':'nadisk_active', 'value':di_active, 'unit':'', 'min':0})
  113. pd = {'label':'nadisk_spare', 'value':di_spare, 'unit':'', 'min':0}
  114. if warn and target=='spare':
  115. pd['warn'] = warn
  116. if crit and target=='spare':
  117. pd['crit'] = crit
  118. perfdata.append(pd)
  119. pd = {'label':'nadisk_failed', 'value':di_failed, 'unit':'', 'min':0}
  120. if warn and target=='failed':
  121. pd['warn'] = warn
  122. if crit and target=='failed':
  123. pd['crit'] = crit
  124. perfdata.append(pd)
  125. return self.remember_check('disk', returncode, output, perfdata=perfdata, target=target)
  126. def check_global(self):
  127. model = self.SNMPGET(self.OID['Model'])
  128. globalstatus = int(self.SNMPGET(self.OID['Global_Status']))
  129. globalstatusmsg = self.SNMPGET(self.OID['Global_Status_Message'])[:255]
  130. returncode = self.map_status_to_returncode(globalstatus, self.OWC['Global_Status'])
  131. output = model + ': ' + globalstatusmsg
  132. return self.remember_check('global', returncode, output)
  133. def check_nvram(self):
  134. nvramstatus = int(self.SNMPGET(self.OID['NVRAM_Status']))
  135. returncode = self.map_status_to_returncode(nvramstatus, self.OWC['NVRAM_Status'])
  136. output = 'NVRAM battery status is "' + self.Status2String['NVRAM_Status'].get(str(nvramstatus)) + '"'
  137. return self.remember_check('nvram', returncode, output)
  138. def check_version(self):
  139. model = self.SNMPGET(self.OID['Model'])
  140. ontapversion = self.SNMPGET(self.OID['ONTAP_Version'])
  141. return self.remember_check('version', 0, model + ': ' + ontapversion)
  142. def common_vol_idx(self, volume):
  143. if volume.endswith('.snapshot'):
  144. return None
  145. idx = str(self.find_in_table(self.OID['df_FS_Index'], self.OID['df_FS_Name'] , volume))
  146. sn_idx = int(idx) + 1
  147. return (idx, sn_idx)
  148. def check_vol_data(self, volume, warn, crit):
  149. (idx, sn_idx) = self.common_vol_idx(volume)
  150. fs_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], idx)) * 1024L
  151. fs_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], idx)) * 1024L
  152. # fs_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], idx)) * 1024L
  153. sn_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], sn_idx)) * 1024L
  154. sn_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], sn_idx)) * 1024L
  155. # sn_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], sn_idx)) * 1024L
  156. mountedon = self.SNMPGET(self.OID['df_FS_Mounted_On'] + "." + idx)
  157. status = self.Status2String['df_FS_Status'].get(self.SNMPGET(self.OID['df_FS_Status'] + "." + idx))
  158. fstype = self.Status2String['df_FS_Type'].get(self.SNMPGET(self.OID['df_FS_Type'] + "." + idx))
  159. fs_pctused = float(fs_used) / float(fs_total) * 100.0
  160. warn = self.range_dehumanize(warn, fs_total)
  161. crit = self.range_dehumanize(crit, fs_total)
  162. returncode = self.value_wc_to_returncode(fs_used, warn, crit)
  163. output = volume + ': Used ' + self.value_to_human_binary(fs_used, 'B')
  164. output += ' (' + '%3.1f' % fs_pctused + '%)'+ ' out of ' + self.value_to_human_binary(fs_total, 'B')
  165. target = volume.replace('/vol/', '')[:-1]
  166. perfdata = []
  167. perfdata.append({'label':'navdu_' + target, 'value':fs_used, 'unit':'B', 'warn':warn, 'crit':crit, 'min':0})
  168. perfdata.append({'label':'navdt_' + target, 'value':fs_total, 'unit':'B'})
  169. perfdata.append({'label':'navsu_' + target, 'value':sn_used, 'unit':'B', 'min':0})
  170. perfdata.append({'label':'navst_' + target, 'value':sn_total, 'unit':'B'})
  171. return self.remember_check('vol_data', returncode, output, perfdata=perfdata, target=target)
  172. def check_vol_snap(self, volume, warn, crit):
  173. (idx, sn_idx) = self.common_vol_idx(volume)
  174. # fs_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], idx)) * 1024L
  175. # fs_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], idx)) * 1024L
  176. # fs_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], idx)) * 1024L
  177. sn_total = long(self.SNMPGET(self.OID['df_FS_kBTotal'], sn_idx)) * 1024L
  178. sn_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], sn_idx)) * 1024L
  179. # sn_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], sn_idx)) * 1024L
  180. sn_pctused = float(sn_used) / float(sn_total) * 100.0
  181. warn = self.range_dehumanize(warn, sn_total)
  182. crit = self.range_dehumanize(crit, sn_total)
  183. returncode = self.value_wc_to_returncode(sn_used, warn, crit)
  184. output = volume + '.snapshot: Used ' + self.value_to_human_binary(sn_used, 'B')
  185. output += ' (' + '%3.1f' % sn_pctused + '%)'+ ' out of ' + self.value_to_human_binary(sn_total, 'B')
  186. target = volume.replace('/vol/', '')[:-1]
  187. perfdata = []
  188. perfdata.append({'label':'navsu_' + target, 'value':sn_used, 'unit':'B', 'warn':warn, 'crit':crit, 'min':0})
  189. perfdata.append({'label':'navst_' + target, 'value':sn_total, 'unit':'B'})
  190. return self.remember_check('vol_snap', returncode, output, perfdata=perfdata, target=target)
  191. def check_vol_inode(self, volume, warn, crit):
  192. (idx, sn_idx) = self.common_vol_idx(volume)
  193. in_used = long(self.SNMPGET(self.OID['df_FS_INodeUsed'] + '.' + idx))
  194. in_free = long(self.SNMPGET(self.OID['df_FS_INodeFree'] + '.' + idx))
  195. in_total = in_used + in_free
  196. in_pctused = float(in_used) / float(in_total) * 100.0
  197. warn = self.range_dehumanize(warn, in_total)
  198. crit = self.range_dehumanize(crit, in_total)
  199. returncode = self.value_wc_to_returncode(in_used, warn, crit)
  200. output = volume + ': Used inodes ' + self.value_to_human_si(in_used)
  201. output += ' (' + '%3.1f' % in_pctused + '%)'+ ' out of ' + self.value_to_human_si(in_total)
  202. target = volume.replace('/vol/', '')[:-1]
  203. perfdata = []
  204. perfdata.append({'label':'naviu_' + target, 'value':in_used, 'unit':None, 'warn':warn, 'crit':crit, 'min':0})
  205. perfdata.append({'label':'navit_' + target, 'value':in_total, 'unit':None})
  206. return self.remember_check('vol_inode', returncode, output, perfdata=perfdata, target=target)
  207. def check_vol_files(self, volume, warn, crit):
  208. (idx, sn_idx) = self.common_vol_idx(volume)
  209. fi_avail = long(self.SNMPGET(self.OID['df_FS_MaxFilesAvail'] + '.' + idx))
  210. fi_used = long(self.SNMPGET(self.OID['df_FS_MaxFilesUsed'] + '.' + idx))
  211. fi_possible = long(self.SNMPGET(self.OID['df_FS_MaxFilesPossible'] + '.' + idx))
  212. fi_total = fi_used + fi_avail
  213. fi_pctused = float(fi_used) / float(fi_total) * 100.0
  214. warn = self.range_dehumanize(warn, fi_total)
  215. crit = self.range_dehumanize(crit, fi_total)
  216. returncode = self.value_wc_to_returncode(fi_used, warn, crit)
  217. output = volume + ': Used files ' + self.value_to_human_si(fi_used)
  218. output += ' (' + '%3.1f' % fi_pctused + '%)'+ ' out of ' + self.value_to_human_si(fi_total)
  219. output += ', may raised to ' + self.value_to_human_si(fi_possible)
  220. target = volume.replace('/vol/', '')[:-1]
  221. perfdata = []
  222. perfdata.append({'label':'navfu_' + target, 'value':fi_used, 'unit':None, 'warn':warn, 'crit':crit, 'min':0})
  223. perfdata.append({'label':'navft_' + target, 'value':fi_total, 'unit':None})
  224. return self.remember_check('vol_files', returncode, output, perfdata=perfdata, target=target)
  225. def main():
  226. plugin = CheckNAF(pluginname='check_naf', tagforstatusline='NAF', description=u'Monitoring NetApp™ FAS systems', version='0.9')
  227. plugin.add_cmdlineoption('', '--check', 'check', 'check or list of checks', default='')
  228. plugin.add_cmdlineoption('', '--target', 'target', 'target or list of targets', default='')
  229. plugin.add_cmdlineoption('-w', '', 'warn', 'warning thresold or a list of it', default='')
  230. plugin.add_cmdlineoption('-c', '', 'crit', 'warning thresold or a list of it', default='')
  231. plugin.parse_cmdlineoptions()
  232. plugin.prepare_snmp()
  233. if ',' in plugin.options.check:
  234. checks = plugin.options.check.split(',')
  235. checks.reverse()
  236. else:
  237. checks = [plugin.options.check,]
  238. if ',' in plugin.options.target:
  239. targets = plugin.options.target.split(',')
  240. else:
  241. targets = [plugin.options.target,]
  242. while len(checks):
  243. check = checks.pop()
  244. target = None
  245. arguments = None
  246. if ':' in check:
  247. target = ':'.join(check.split(':')[1:])
  248. check = check.split(':')[0]
  249. if ':' in target:
  250. arguments = ':'.join(target.split(':')[1:])
  251. target = target.split(':')[0]
  252. if check == 'global':
  253. result = plugin.check_global()
  254. elif check == 'cpu':
  255. result = plugin.check_cpu()
  256. elif check == 'disk':
  257. result = plugin.check_disk(target=target)
  258. elif check == 'nvram':
  259. result = plugin.check_nvram()
  260. elif check == 'version':
  261. result = plugin.check_version()
  262. elif check.startswith('vol_'):
  263. combinedchecks = [check,]
  264. while len(checks) > 0 and checks[0].startswith('vol_'):
  265. combinedchecks.append(checks.pop())
  266. for target in targets:
  267. for check in combinedchecks:
  268. if check == 'vol_data':
  269. result = plugin.check_vol_data(target, plugin.options.warn, plugin.options.crit)
  270. elif check == 'vol_snap':
  271. result = plugin.check_vol_snap(target, plugin.options.warn, plugin.options.crit)
  272. elif check =='vol_inode':
  273. result = plugin.check_vol_inode(target, plugin.options.warn, plugin.options.crit)
  274. elif check =='vol_files':
  275. result = plugin.check_vol_files(target, plugin.options.warn, plugin.options.crit)
  276. # from pprint import pprint
  277. # pprint(plugin.dump_brain())
  278. plugin.brain2output()
  279. plugin.exit()
  280. if __name__ == '__main__':
  281. main()
  282. #vim: ts=4 sw=4 foldmethod=indent