Let the external IP of the Zabbix server be - 30.0.1.1
Local Zabbix Server IP - 10.3.10.1
Test node address - 30.0.1.3
By forwarding ports here will not be said. The node in the example will listen to 10050, the server - 10051.
conf - there will be a config file
disks - disk information in JSON will be generated here
logs
pks - there will be a Z_agent.psk file containing the pre-shared key
scripts
smartmontools - put the SMART program of the same name here
#!/bin/bash echo -n " ? : " read LIMIT a=1 echo \# > /home/appliance/agent_psk while [ "$a" -le $LIMIT ] do openssl rand -hex 64 >> /home/appliance/agent_psk let "a++" done less /home/appliance/agent_psk
c:\>"Program Files"\smartmontools\bin\smartctl.exe --scan
c:\>"Program Files"\smartmontools\bin\smartctl.exe -i /dev/sda -d ata
c:\>"Program Files\smartmontools\bin\smartctl.exe" --smart=on --offlineauto=on --saveauto=on /dev/sda
c:\>"Program Files"\smartmontools\bin\smartctl.exe -A /dev/sda -d ata
c:\>"Program Files"\smartmontools\bin\smartctl.exe -H /dev/sda -d ata
Macro {#DISKPORT} - the name of the disk in the system (/ dev / sda, / dev / sdb, etc.),
Macro {#DISKTYPE} - disk type (ata, scsi, sat, csmi, etc.),
Macro {#DISKMODEL} - disk model,
Macro {#DISKSN} - serial number.
@echo off echo @echo off > c:\zabbix\disks\disks.cmd echo echo {"data": >> c:\zabbix\disks\disks.cmd echo echo [ >> c:\zabbix\disks\disks.cmd for /F "tokens=1,3" %%a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe --scan') ^ do (for %%s in ("Device Model" "Product") ^ do (for /F "tokens=2*" %%c in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -i %%a -d %%b ^| find %%s ') ^ do (for %%i in ("Serial Number") do (for /F "tokens=3*" %%k in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -i %%a -d %%b ^| find %%i ') ^ do echo echo {"{#DISKPORT}":"%%a","{#DISKTYPE}":"%%b","{#DISKMODEL}":"%%d","{#DISKSN}":"%%k"},>> c:\zabbix\disks\disks.cmd)))) echo echo {"{#SMARTV}":"Smartctl 6.5"}>> c:\zabbix\disks\disks.cmd echo echo ] >> c:\zabbix\disks\disks.cmd echo echo } >> c:\zabbix\disks\disks.cmd
{"{#DISKPORT}":"%%a","{#DISKTYPE}":"%%b","{#DISKMODEL}":"%%d","{#DISKSN}":"%%k"},
rem : for /F "tokens=1" %%a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe --scan') ^ do "C:\Program Files\smartmontools\bin\smartctl.exe" --smart=on --offlineauto=on --saveauto=on %%a
LogFile=C:\zabbix\logs\logs.log # LogFileSize=100 # Server=30.0.1.1 # ServerActive=30.0.1.1 # StartAgents=3 # - - Timeout=30 # 30 Hostname= # # TLS TLSConnect=psk # ( ) TLSAccept=psk # ( ) TLSPSKFile=C:\zabbix\psk\Z_agent.psk # pre-shared TLSPSKIdentity= #
@echo off chcp 866 > nul set /P CLIENT="Enter Organization name: " set /P PSKID=" Enter PSKIdentity: " set /P PSKkey="Enter PSKkey: " rem @echo # zabbix_agent 3.0.1> C:\zabbix\conf\zabbix_agentd.conf @echo. >>C:\zabbix\conf\zabbix_agentd.conf @echo %PSKkey%>>C:\zabbix\psk\Z_agent.psk @echo LogFile=C:\zabbix\logs\logs.log >> C:\zabbix\conf\zabbix_agentd.conf @echo LogFileSize=100 >> C:\zabbix\conf\zabbix_agentd.conf @echo Server=30.0.1.1 >> C:\zabbix\conf\zabbix_agentd.conf @echo ServerActive=30.0.1.1 >> C:\zabbix\conf\zabbix_agentd.conf @echo StartAgents=3 >> C:\zabbix\conf\zabbix_agentd.conf @echo Timeout=30 >> C:\zabbix\conf\zabbix_agentd.conf @echo Hostname=%CLIENT%.%COMPUTERNAME%>> C:\zabbix\conf\zabbix_agentd.conf @echo. >> C:\zabbix\conf\zabbix_agentd.conf @echo ##### TLS ###########>> C:\zabbix\conf\zabbix_agentd.conf @echo TLSConnect=psk>> C:\zabbix\conf\zabbix_agentd.conf @echo TLSAccept=psk>> C:\zabbix\conf\zabbix_agentd.conf @echo TLSPSKFile=C:\zabbix\psk\Z_agent.psk>> C:\zabbix\conf\zabbix_agentd.conf @echo TLSPSKIdentity=%PSKID%>> C:\zabbix\conf\zabbix_agentd.conf @echo. >> C:\zabbix\conf\zabbix_agentd.conf
##### . UserParameter=HDD.discovery,for /F "tokens=*" %a in ('C:\zabbix\disks\disks.cmd') do @echo %a ##### SMART # RAW_VALUE UserParameter=HDD.raw[*], for /F "tokens=10" %a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -A $1 -d $2 ^| find "$3"') do @echo %a # VALUE UserParameter=HDD.value.[*], for /F "tokens=4" %a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -A $1 -d $2^| find "$3"') do @echo %a # WORST UserParameter=HDD.worst.[*], for /F "tokens=5" %a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -A $1 -d $2 ^| find "$3"') do @echo %a # THRESOLD UserParameter=HDD.thresh.[*], for /F "tokens=6" %a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -A $1 -d $2 ^| find "$3"') do @echo %a # WHEN_FAILED UserParameter=HDD.when.failed.[*], for /F "tokens=9" %a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -A $1 -d $2 ^| find "$3"') do @echo %a # HEALTH Status UserParameter=HDD.health.[*], for /F "tokens=6" %a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -H $1 -d $2 ^| find "test"') do @echo %a
type C:\zabbix\scripts\UserParameters.txt>> C:\zabbix\conf\zabbix_agentd.conf
@echo off set localportname=10050 set rulename=zabbix set dirrname=in set protocolname=TCP set actionname=allow netsh advfirewall firewall add rule name=%rulename% dir=%dirrname% action=%actionname% protocol=%protocolname% localport=%localportname%
@echo off chcp 866 > nul set /P CLIENT="Client NAME: " set /P PSKID="PSKIdentity: " set /P PSKkey="Enter PSKkey: " cls rem smartmontools C:\zabbix\smartmontools\smartmontools-6.5-1.win32-setup.exe /S rem 10050 set localportname=10050 set rulename=zabbix set dirrname=in set protocolname=TCP set actionname=allow netsh advfirewall firewall add rule name=%rulename% dir=%dirrname% action=%actionname% protocol=%protocolname% localport=%localportname% echo "port %localportname% was open on host %hostname%" rem @echo # zabbix_agent 3.0.1> C:\zabbix\conf\zabbix_agentd.conf @echo. >>C:\zabbix\conf\zabbix_agentd.conf @echo %PSKkey%>C:\zabbix\psk\Z_agent.psk @echo LogFile=C:\zabbix\logs\logs.log >> C:\zabbix\conf\zabbix_agentd.conf @echo LogFileSize=100 >> C:\zabbix\conf\zabbix_agentd.conf @echo Server=30.0.1.1 >> C:\zabbix\conf\zabbix_agentd.conf @echo ServerActive=30.0.1.1 >> C:\zabbix\conf\zabbix_agentd.conf @echo StartAgents=3 >> C:\zabbix\conf\zabbix_agentd.conf @echo Timeout=30 >> C:\zabbix\conf\zabbix_agentd.conf @echo Hostname=%CLIENT%.%COMPUTERNAME%>> C:\zabbix\conf\zabbix_agentd.conf @echo. >> C:\zabbix\conf\zabbix_agentd.conf @echo ##### TLS ###########>> C:\zabbix\conf\zabbix_agentd.conf @echo TLSConnect=psk>> C:\zabbix\conf\zabbix_agentd.conf @echo TLSAccept=psk>> C:\zabbix\conf\zabbix_agentd.conf @echo TLSPSKFile=C:\zabbix\psk\Z_agent.psk >> C:\zabbix\conf\zabbix_agentd.conf @echo TLSPSKIdentity=%PSKID%> C:\zabbix\conf\zabbix_agentd.conf @echo. >> C:\zabbix\conf\zabbix_agentd.conf rem type C:\zabbix\scripts\UserParameters.txt>> C:\zabb\conf\zabbix_agentd.conf rem @echo off echo @echo off > c:\zabbix\disks\disks.cmd echo echo {"data": >> c:\zabbix\disks\disks.cmd echo echo [ >> c:\zabbix\disks\disks.cmd for /F "tokens=1,3" %%a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe --scan') ^ do (for %%s in ("Device Model" "Product") ^ do (for /F "tokens=2*" %%c in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -i %%a -d %%b ^| find %%s ') ^ do (for %%i in ("Serial Number") do (for /F "tokens=3*" %%k in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -i %%a -d %%b ^| find %%i ') ^ do echo echo {"{#DISKPORT}":"%%a","{#DISKTYPE}":"%%b","{#DISKMODEL}":"%%d","{#DISKSN}":"%%k"},>> c:\zabbix\disks\disks.cmd)))) echo echo {"{#SMARTV}":"Smartctl 6.5"}>> c:\zabbix\disks\disks.cmd echo echo ] >> c:\zabbix\disks\disks.cmd echo echo } >> c:\zabbix\disks\disks.cmd rem for /F "tokens=1" %%a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe --scan') ^ do "C:\Program Files\smartmontools\bin\smartctl.exe" --smart=on --offlineauto=on --saveauto=on %%a rem Zabbix Agent if DEFINED ProgramFiles(x86) (goto :x64) else (goto :x86) :x64 C:\zabbix\bin\win64\zabbix_agentd.exe -i -c C:\zabbix\conf\zabbix_agentd.conf goto :NEXT :x86 C:\zabbix\bin\win32\zabbix_agentd.exe -i -c C:\zabbix\conf\zabbix_agentd.conf goto :NEXT :NEXT rem Zabbix Agent net start "Zabbix Agent" echo. echo OK! @echo ------------------------------------ @echo Hostname: %CLIENT%.%COMPUTERNAME% @echo ------------------------------------ @echo. Pause
UserParameter=HDD.discovery,for /F "tokens=*" %a in ('C:\zabbix\disks\disks.cmd') do @echo %a
UserParameter=HDD.value.[*], for /F "tokens=4" %a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -A $1 -d $2^| find "$3"') do @echo %a UserParameter=HDD.thresh.[*], for /F "tokens=6" %a in ('C:\"Program Files"\smartmontools\bin\smartctl.exe -A $1 -d $2 ^| find "$3"') do @echo %a
root@zabbix:~# zabbix_get -s 30.0.1.3 -k HDD.value.[/dev/sda,ata,Spin_Retry_Count] --tls-connect psk --tls-psk-identity "ZP10001AA" --tls-psk-file /root/Organization1.SUNSET.psk
({SMART:HDD.value.[{#DISKPORT},{#DISKTYPE},Spin_Retry_Count].last()}-{SMART:HDD.thresh.[{#DISKPORT},{#DISKTYPE},Spin_Retry_Count].last()})<0
: {#DISKPORT} : {#DISKTYPE} : {#DISKMODEL} : {#DISKSN} : Threshold — : Value Threshold — ; — . , SMART, «Good» «Bad». VALUE THRESH Pre-fail - , 24 . / Spin_Retry_Count / , . , .
! : {TRIGGER.SEVERITY} : {HOST.NAME} : {HOST.DESCRIPTION} : {EVENT.DATE} : {EVENT.TIME} {TRIGGER.NAME} : {TRIGGER.DESCRIPTION} . : 1. {ITEM.NAME1} = {ITEM.VALUE1}. : {ITEM.KEY1} 2. {ITEM.NAME2} = {ITEM.VALUE2}. : {ITEM.KEY2} {TRIGGER.EXPRESSION} Event ID: {EVENT.ID}
"{EVENT.ID}" . : {HOST.NAME} : {HOST.DESCRIPTION} : {EVENT.DATE} {EVENT.TIME} : {EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME} : {TRIGGER.NAME} : {TRIGGER.SEVERITY} : : 1. {ITEM.NAME1} = {ITEM.VALUE1}. : {ITEM.KEY1} 2. {ITEM.NAME2} = {ITEM.VALUE2}. : {ITEM.KEY2} URL: {TRIGGER.URL} Event ID: {EVENT.ID}
({SMART:HDD.value.[{#DISKPORT},{#DISKTYPE},Spin_Retry_Count].last()}-{SMART:HDD.thresh.[{#DISKPORT},{#DISKTYPE},Spin_Retry_Count].last()})>0
Source: https://habr.com/ru/post/309172/
All Articles