Skip to content

Commit

Permalink
Agent 3.4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodysu committed Sep 6, 2017
1 parent 277b88d commit 10677a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ zabbix_get -s 192.0.2.1 -k smartctl.discovery[getverb,"Example host"]
Verbose mode. Does not detaches or prints LLD. Lists all items sent to zabbix-sender, also it is possible to see sender output in this mode.
<br /><br />

Note: before scripts would work, zabbix server must first discover available items. It is done in 12 hour cycles by default. You can temporary decrease this parameter for testing in `template -> Discovery -> SMART disk discovery -> Update interval`.
Note: before scripts would work, zabbix server must first discover available items. It is done in 6 hour cycles by default. You can temporary decrease this parameter for testing in `template -> Discovery -> SMART disk discovery -> Update interval`. In this case update value must not be less than 60 seconds.

These scripts were tested to work with following configurations:
- Centos 7 / Zabbix 2.4 / Python 3.4
- Debian 8 / Zabbix 2.4 / Python 3.4
- Debian 8 / ZS (2.4, 3.4) / ZA (2.4, 3.0, 3.2, 3.4) / Python 3.4
- FreeBSD 10.1 / Zabbix 2.4 / Python 3.4
- Windows XP / Zabbix 2.4 / Python 3.4
- Windows 7 / Zabbix 2.4 / Python 3.4
- Windows 7 / ZS (2.4, 3.4) / ZA (2.4, 3.0, 3.2, 3.4) / Python 3.4
- Windows Server 2012 / Zabbix 2.4 / Python 3.4

## Updating
### from any to 1.3, 1.4 or 1.5:<br />
### from any to 1.3, 1.4, 1.5, 1.5.1:<br />
Replace all old files with new ones and reupload the template.

## Issues
- Zabbix web panel displays an error on json discovery, but apparently everything works fine
- Windows version does not detaches currently, and data will only be gathered on second pass
- Windows version does not detaches, and data will only be gathered on second pass (probably permanent workaround)

## Planned features
- SSD life monitoring, TRIM capability
Expand Down
19 changes: 11 additions & 8 deletions scripts/smartctl-lld.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Installation instructions: https://github.com/nobodysu/zabbix-smartmontools

mode = 'device' # 'device' or 'serial' as primary identifier in zabbix item's name
# 'serial' is much safer for multi-disk system

ctlPath = r'smartctl'
#ctlPath = r'C:\Program Files\smartmontools\bin\smartctl.exe' # if smartctl isn't in PATH
Expand All @@ -22,6 +23,7 @@
#senderPath = r'C:\zabbix-agent\bin\win32\zabbix_sender.exe' # Win

timeout = '60' # how long the script must wait between LLD and sending, increase if data received late (does not affect windows)
# this setting MUST be lower than 'Update interval' in discovery rule

# manually provide disk list or RAID configuration if needed
diskListManual = []
Expand All @@ -37,6 +39,12 @@
from json import dumps
from shlex import split

# intended for 'python3' binary but can be changed in special cases, alongside with shebang
if sys.platform != 'win32': # if not windows
pythonCmd = 'python3'
else:
pythonCmd = 'python.exe'

hostname = '"' + sys.argv[2] + '"'

jsonData = []
Expand Down Expand Up @@ -194,21 +202,16 @@ def replace_all(string, stopChars):

senderDataNStr = '\n'.join(senderData) # items for zabbix sender separated by newlines

if sys.platform != 'win32': # if not windows
pythonCmd = 'python3'
else:
pythonCmd = 'python.exe'

# pass senderDataNStr to smartctl-send.py:
if sys.argv[1] == 'get':
print(dumps({"data": jsonData}, indent=4)) # print data gathered for LLD

subprocess.Popen([pythonCmd, senderPyPath, 'get', agentConf, senderPath, timeout, senderDataNStr], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # spawn new process and regain shell control immediately (only *nix, windows waits)
subprocess.Popen([pythonCmd, senderPyPath, 'get', agentConf, senderPath, timeout, senderDataNStr], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # spawn new process and regain shell control immediately (on Win 'smartctl-send.py' will not wait)

elif sys.argv[1] == 'getverb':
subprocess.Popen([pythonCmd, senderPyPath, 'getverb', agentConf, senderPath, timeout, senderDataNStr], stdin=subprocess.PIPE) # do not detach if in verbose mode, also skips timeout in smartctl-send.py
subprocess.Popen([pythonCmd, senderPyPath, 'getverb', agentConf, senderPath, timeout, senderDataNStr], stdin=subprocess.PIPE) # do not detach if in verbose mode, also skips timeout in 'smartctl-send.py'

else:
print(sys.argv[0] + " : Not supported. Use 'get' or 'getverb'.")
sys.exit(1)
#sys.exit(1) # it's safer to just disable error codes after 3.4 changes

0 comments on commit 10677a5

Please sign in to comment.