SMART HDDモニタリング-Windows + Python + ZABBIX

次のプログラムをダウンロードしてインストールします。



Python 3.6.4

SMART Montools



%username%をシステム上のユーザー名に変更することを忘れないでください。 フルパスは、Python 3.6.4をインストールすることで取得できます



システム管理者に代わってインストールを開始する必要があることを忘れないでください。



このコードは、コマンドラインから2つのパラメーター(ディスクの名前と表示するパラメーター)を取ります。 パラメータなしで起動する場合、ディスクが検出され、出力はzabbix-serverを受け入れる既製のフォーマットになります。



利用可能な任意のディレクトリにコードを拡散します。 主なことは、UserParameterで同じパスを指定することです



from subprocess import Popen, PIPE, check_output import re import json import sys import hashlib path = '\"C:\\Program Files\\smartmontools\\bin\\smartctl\"' # for linux use 'sudo smartctl' smart_params = ['Model_Family', 'Device_Model', 'Serial_Number', 'test_result', 'Firmware_Version'] # if u need more \ # add ur data to this list codec = 'windows-1252' # for linux use utf8 def params(disk_name, raw_data=""): # Pars output from smartctl if raw_data not in smart_params and raw_data != "": # Pars smartctl data from sensors (smartctl -A /dev/sd*) out_data = re.findall(r'{}.*- *(\d+)'.format(raw_data), Popen('{} -x /dev/{}'.format(path, disk_name), shell=True, stdout=PIPE, ).communicate()[0].decode(codec)) return out_data[0] elif raw_data != "" and raw_data in smart_params: # Pars smartctl information about disks (smartctl -i /dev/sd*) out_data = re.findall(r'{}. *(.*)'.format(raw_data.replace('_', ' ')), Popen('{} -x /dev/{}'.format(path, disk_name), shell=True, stdout=PIPE, ).communicate()[0].decode(codec)) return out_data[0] elif raw_data == "": # check sum of smartctl --scan hash_object = hashlib.sha224(check_output(path + " --scan")) return hash_object.hexdigest() try: # if no argumens from cli works as discovery try: if sys.argv[1] and sys.argv[2]: print(params(sys.argv[1], sys.argv[2])) except IndexError: print(params(sys.argv[1])) except IndexError: # Discovery for disks data = check_output(path + " --scan").decode(codec) disks = set(re.findall(r'/dev/(.{3})', data)) output = [] for disk in disks: smart = check_output(path + " -i /dev/{}".format(disk)).decode(codec) if smart: output.append({"{#DISKNAME}": disk, "{#SMART_ENABLED}": "1"}) else: output.append({"{#DISKNAME}": disk, "{#SMART_ENABLED}": "0"}) output = {"data": output} print(json.dumps(output))
      
      





zabbix-agentd.confの監視対象ホスト上で、またはIncludeセクションを開いている場合は、その中に定義されているファイルで、以下にリストされているUserParametersを追加します



 UserParameter=uHDD.discovery,C:\\Users\\%username%\\AppData\\Local\\Programs\\Python\\Python36-32\\python.exe C:\\zabbix\\lld\\hdd_discovery.py UserParameter=uHDD[*],C:\\Users\\%username%\\AppData\\Local\\Programs\\Python\\Python36-32\\python.exe C:\\zabbix\\lld\\hdd_discovery.py $1 $2
      
      





Zabbixサーバーにテンプレートを追加する



gitにレイアウト -カブ全体が非常にポジティブだとは思わない-私は学んでいる:)



テンプレートをダウンロードします-サーバーにインポートし、監視対象ホストに追加します。

独自のデータ項目を追加できます。 ロジックは次のとおりです。データ要素はスクリプトにパラメーターを送信し、smartctlの出力を解析します。何かを追加したい場合は問題ありません。これを行うのに役立つコメントがコードにあります。



怠け者のためのPSスクリプト。 Linuxでは、同じドライブの同じ監視が1年間機能し、Windowsに到達しました。



All Articles