Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nikimaxim authored Aug 14, 2020
1 parent 6afa70f commit f2069ac
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 41 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#### Get utils smartmontools
- https://builds.smartmontools.org/
- Installing from package: Ubuntu(sudo apt install smartmontools), CentOS(yum install smartmontools)

#### Copy bash script:
- **github**/smartctl-storage-discovery.sh in /opt/zabbix/smartctl-storage-discovery.sh
Expand Down
80 changes: 61 additions & 19 deletions Template smartmonitor.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>5.0</version>
<date>2020-08-01T17:09:21Z</date>
<date>2020-08-14T11:54:38Z</date>
<groups>
<group>
<name>Templates Users</name>
Expand Down Expand Up @@ -69,6 +69,12 @@
<name>SMART monitoring (smartctl)</name>
</application>
</applications>
<preprocessing>
<step>
<type>JAVASCRIPT</type>
<params>return value.replace(/\s\(.+\)|\s\[.+\]|[\u00A0]/g, '') // Deleting data in brackets and spaces</params>
</step>
</preprocessing>
<trigger_prototypes>
<trigger_prototype>
<expression>{str(&quot;FAILING_NOW&quot;)}=1</expression>
Expand All @@ -94,6 +100,8 @@
<delay>0</delay>
<trends>0</trends>
<value_type>CHAR</value_type>
<description>HDD&#13;
SSD</description>
<applications>
<application>
<name>SMART monitoring (smartctl)</name>
Expand Down Expand Up @@ -138,6 +146,9 @@
<delay>0</delay>
<trends>0</trends>
<value_type>CHAR</value_type>
<description>HDD&#13;
SSD&#13;
NVME</description>
<applications>
<application>
<name>SMART monitoring (smartctl)</name>
Expand All @@ -161,6 +172,9 @@
<delay>0</delay>
<trends>0</trends>
<value_type>CHAR</value_type>
<description>HDD&#13;
SSD&#13;
NVME</description>
<applications>
<application>
<name>SMART monitoring (smartctl)</name>
Expand Down Expand Up @@ -192,8 +206,7 @@
<key>storage[&quot;{#STORAGE.CMD}&quot;, 05 Reallocated_Sector_Ct]</key>
<delay>0</delay>
<description>HDD&#13;
SSD&#13;
NVME</description>
SSD</description>
<applications>
<application>
<name>SMART monitoring (smartctl)</name>
Expand Down Expand Up @@ -247,13 +260,9 @@ NVME</description>
</application>
</applications>
<preprocessing>
<step>
<type>JAVASCRIPT</type>
<params>return value.replace(/[\u00A0]/g, '')</params>
</step>
<step>
<type>REGEX</type>
<params>(?:9 Power_On_Hours|Power On Hours:).+ ([^\(\d*\)]\d+)
<params>(?:9 Power_On_Hours|Power On Hours:|[Nn]umber of hours powered up|Accumulated power on time).+ ([0-9]+)
\1</params>
</step>
<step>
Expand Down Expand Up @@ -281,7 +290,7 @@ NVME</description>
<preprocessing>
<step>
<type>REGEX</type>
<params>10 Spin_Retry_Count.+ ([0-9]+)
<params>(?:10 Spin_Retry_Count).+ ([0-9]+)
\1</params>
<error_handler>CUSTOM_ERROR</error_handler>
<error_handler_params>Not supported</error_handler_params>
Expand Down Expand Up @@ -314,10 +323,6 @@ NVME</description>
</application>
</applications>
<preprocessing>
<step>
<type>JAVASCRIPT</type>
<params>return value.replace(/\s\(.+\)/g, ' ')</params>
</step>
<step>
<type>REGEX</type>
<params>(?:190 Temperature|190 Airflow_Temperature|194 Temperature|Drive Temperature:|Temperature:).+ ([0-9]+)
Expand All @@ -335,20 +340,20 @@ NVME</description>
{last()}&lt;=100</expression>
<recovery_mode>RECOVERY_EXPRESSION</recovery_mode>
<recovery_expression>{avg(5m)}&lt;{$TEMP_CRIT}-3</recovery_expression>
<name>{#STORAGE.NAME}: Disk temperature: {ITEM.LASTVALUE}</name>
<name>{#STORAGE.NAME}: Disk temperature CRITICAL</name>
<priority>AVERAGE</priority>
<manual_close>YES</manual_close>
</trigger_prototype>
<trigger_prototype>
<expression>{avg(5m)}&gt;{$TEMP_WARN}</expression>
<recovery_mode>RECOVERY_EXPRESSION</recovery_mode>
<recovery_expression>{avg(5m)}&lt;{$TEMP_WARN}-3</recovery_expression>
<name>{#STORAGE.NAME}: Disk temperature: {ITEM.LASTVALUE}</name>
<name>{#STORAGE.NAME}: Disk temperature WARNING</name>
<priority>WARNING</priority>
<manual_close>YES</manual_close>
<dependencies>
<dependency>
<name>{#STORAGE.NAME}: Disk temperature: {ITEM.LASTVALUE}</name>
<name>{#STORAGE.NAME}: Disk temperature CRITICAL</name>
<expression>{Template SMARTMONTOOLS:storage[&quot;{#STORAGE.CMD}&quot;, 190/194 Temperature_Celsius].avg(5m)}&gt;{$TEMP_CRIT} and&#13;
{Template SMARTMONTOOLS:storage[&quot;{#STORAGE.CMD}&quot;, 190/194 Temperature_Celsius].last()}&lt;=100</expression>
<recovery_expression>{Template SMARTMONTOOLS:storage[&quot;{#STORAGE.CMD}&quot;, 190/194 Temperature_Celsius].avg(5m)}&lt;{$TEMP_CRIT}-3</recovery_expression>
Expand All @@ -371,7 +376,7 @@ NVME</description>
<preprocessing>
<step>
<type>REGEX</type>
<params>197 Current_Pending_Sector.+ ([0-9]+)
<params>(?:197 Current_Pending_Sector|197 ).+ ([0-9]+)
\1</params>
<error_handler>CUSTOM_ERROR</error_handler>
<error_handler_params>Not supported</error_handler_params>
Expand Down Expand Up @@ -419,7 +424,7 @@ SSD</description>
<preprocessing>
<step>
<type>REGEX</type>
<params>Offline_Uncorrectable.+ ([0-9]+)
<params>(?:Offline_Uncorrectable).+ ([0-9]+)
\1</params>
<error_handler>CUSTOM_ERROR</error_handler>
<error_handler_params>Not supported</error_handler_params>
Expand Down Expand Up @@ -453,7 +458,8 @@ SSD</description>
<key>storage[&quot;{#STORAGE.CMD}&quot;, 199/218 UDMA_CRC_Error]</key>
<delay>0</delay>
<description>HDD&#13;
SSD</description>
SSD&#13;
NVME</description>
<applications>
<application>
<name>SMART monitoring (smartctl)</name>
Expand All @@ -480,6 +486,42 @@ SSD</description>
</trigger_prototype>
</trigger_prototypes>
</item_prototype>
<item_prototype>
<name>{#STORAGE.NAME}: ID 231 SSD life left</name>
<type>DEPENDENT</type>
<key>storage[&quot;{#STORAGE.CMD}&quot;, 231 SSD_Life_Left]</key>
<delay>0</delay>
<units>%</units>
<description>SSD&#13;
NVME</description>
<applications>
<application>
<name>SMART monitoring (smartctl)</name>
</application>
</applications>
<preprocessing>
<step>
<type>REGEX</type>
<params>(?:231 SSD_Life_Left |Available Spare: |231 ).+ ([0-9]+)
\1</params>
<error_handler>CUSTOM_ERROR</error_handler>
<error_handler_params>Not supported</error_handler_params>
</step>
</preprocessing>
<master_item>
<key>storage.get[&quot;{#STORAGE.CMD}&quot;]</key>
</master_item>
<trigger_prototypes>
<trigger_prototype>
<expression>{last()}&lt;=10</expression>
<recovery_mode>RECOVERY_EXPRESSION</recovery_mode>
<recovery_expression>{last()}&gt;10</recovery_expression>
<name>{#STORAGE.NAME}: SMART SSD life left</name>
<priority>AVERAGE</priority>
<manual_close>YES</manual_close>
</trigger_prototype>
</trigger_prototypes>
</item_prototype>
</item_prototypes>
<graph_prototypes>
<graph_prototype>
Expand Down
18 changes: 9 additions & 9 deletions smartctl-storage-discovery.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#
.VERSION
0.3
0.4
.DESCRIPTION
Author: Nikitin Maksim
Expand Down Expand Up @@ -68,12 +68,6 @@ foreach ($device in $smart_scan) {
$storage_smart = 1
}

# Device NVMe and SMART
if ($storage_args -like "*nvme*" -or $storage_name -like "*nvme*") {
$storage_type = 1
$storage_smart = 1
}

# Get device model(For different types of devices)
$d = (($info | Select-String "Device Model:") -replace "Device Model:")
if ($d) {
Expand All @@ -97,13 +91,19 @@ foreach ($device in $smart_scan) {
}
}

# 0 is for HDD
# 1 is for SSD/NVMe
# Get device type:
# - 0 is for HDD
# - 1 is for SSD
# - 1 is for NVMe
$rotation_rate = $info | Select-String "Rotation Rate:"
if ($rotation_rate -like "*rpm*") {
$storage_type = 0
} elseif ($rotation_rate -like "*Solid State Device*") {
$storage_type = 1
} elseif ($storage_args -like "*nvme*" -or $storage_name -like "*nvme*") {
# Device NVMe and SMART
$storage_type = 1
$storage_smart = 1
}

# Adding a split sign when multiple disks are detected
Expand Down
26 changes: 15 additions & 11 deletions smartctl-storage-discovery.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#
# .VERSION
# 0.3
# 0.4
#
# .DESCRIPTION
# Author: Nikitin Maksim
Expand All @@ -14,6 +14,10 @@

CTL='/usr/sbin/smartctl'

if [[ ! -x "$CTL" ]]; then
echo "Could not find path: $CTL"
exit
fi

LLDSmart()
{
Expand Down Expand Up @@ -60,12 +64,6 @@ LLDSmart()
storage_smart=1
fi

# Device NVMe and SMART
if [[ $storage_args == *"nvme"* ]] || [[ $storage_name == *"nvme"* ]]; then
storage_type=1
storage_smart=1
fi

# Get device model(For different types of devices)
d=$(/bin/echo $temp_info | grep "Device Model:" | cut -f2 -d":" | sed -e 's/^\s*//')
if [ -n $d ]; then
Expand All @@ -89,12 +87,18 @@ LLDSmart()
fi
fi

# 0 is for HDD
# 1 is for SSD/NVMe
if [ -n $(/bin/echo $temp_info | grep -iE "^Rotation Rate:\s*rpm\s*$") ]; then
# Get device type:
# - 0 is for HDD
# - 1 is for SSD
# - 1 is for NVMe
if [ -n "$(/bin/echo $temp_info | grep -iE "^Rotation Rate:.*rpm.*$")" ]; then
storage_type=0
elif [ -n $(/bin/echo $temp_info | grep -iE "^Rotation Rate:\s*Solid State Device\s*$") ]; then
elif [ -n "$(/bin/echo $temp_info | grep -iE "^Rotation Rate:\s*Solid State Device\s*$")" ]; then
storage_type=1
elif [[ $storage_args == *"nvme"* ]] || [[ $storage_name == *"nvme"* ]]; then
# Device NVMe and SMART
storage_type=1
storage_smart=1
fi

storage_info="{\"{#STORAGE.SN}\":\"${storage_sn}\",\"{#STORAGE.MODEL}\":\"${storage_model}\",\"{#STORAGE.NAME}\":\"${storage_name}\",\"{#STORAGE.CMD}\":\"${storage_cmd}\",\"{#STORAGE.SMART}\":\"${storage_smart}\",\"{#STORAGE.TYPE}\":\"${storage_type}\"},"
Expand Down
4 changes: 2 additions & 2 deletions zabbix_agentd.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Windows smartctl monitor
UserParameter=storage.get[*],for /F "tokens=* usebackq" %a in (`""C:\Program Files\smartmontools\bin\smartctl.exe" -i -H -A -l error -l background $1"`) do @echo %a
UserParameter=storage.discovery[*],powershell -NoProfile -ExecutionPolicy Bypass -File "C:\service\smartctl-storage-discovery.ps1"
UserParameter=storage.get[*],for /F "tokens=* usebackq" %a in (`""C:\Program Files\smartmontools\bin\smartctl.exe" -i -H -A -l error -l background $1"`) do @echo %a
UserParameter=smartctl.version,powershell -NoProfile -ExecutionPolicy Bypass -Command "(((& 'C:\Program Files\smartmontools\bin\smartctl.exe' --version | Where-Object {$_ -match '^smartctl\s\d'}) -ireplace 'smartctl\s') -ireplace '\s\[.+$').Trim()"

# Linux smartctl monitor
UserParameter=storage.discovery[*],sudo /opt/zabbix/smartctl-storage-discovery.sh
UserParameter=storage.get[*],sudo smartctl -i -H -A -l error -l background $1
UserParameter=storage.discovery[*],sudo /opt/zabbix_s/smartctl-storage-discovery.sh
UserParameter=smartctl.version,smartctl --version | grep -Eo "^smartctl\s[0-9\.[:space:]\r-]+" | sed -e 's/^smartctl\s//'

0 comments on commit f2069ac

Please sign in to comment.