Skip to content

Commit

Permalink
compatibility with zabbix-smartmontools
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodysu committed Jun 1, 2018
1 parent b0f653c commit cd2b743
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
7 changes: 5 additions & 2 deletions BSD/mini_ipmi_bsdcpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import sys
import subprocess
import re
from sender_wrapper import (readConfig, processData)
from sender_wrapper import (readConfig, processData, fail_ifNot_Py3)


def getOutput():
Expand Down Expand Up @@ -79,6 +79,8 @@ def getCpuData():


if __name__ == '__main__':
fail_ifNot_Py3()

host = '"' + sys.argv[2] + '"' # hostname
senderData = []
jsonData = []
Expand All @@ -99,5 +101,6 @@ def getCpuData():
if not statusC:
senderData.append('%s mini.cpu.info[ConfigStatus] "%s"' % (host, getOutput_Out[0])) # OS_NOCMD, OS_ERROR, UNKNOWN_EXC_ERROR, CONFIGURED

processData(senderData, jsonData, agentConf, senderPyPath, senderPath, timeout, host)
link = r'https://github.com/nobodysu/zabbix-mini-IPMI/issues'
processData(senderData, jsonData, agentConf, senderPyPath, senderPath, timeout, host, link)

7 changes: 5 additions & 2 deletions Linux/mini_ipmi_lmsensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import sys
import subprocess
import re
from sender_wrapper import (readConfig, processData)
from sender_wrapper import (readConfig, processData, fail_ifNot_Py3)


def getOutput():
Expand Down Expand Up @@ -254,6 +254,8 @@ def getCpuData():


if __name__ == '__main__':
fail_ifNot_Py3()

host = '"' + sys.argv[2] + '"' # hostname
senderData = []
jsonData = []
Expand Down Expand Up @@ -299,4 +301,5 @@ def getCpuData():
if not statusC:
senderData.append('%s mini.cpu.info[ConfigStatus] "%s"' % (host, getOutput_Out[0])) # OS_NOCMD, OS_ERROR, UNKNOWN_EXC_ERROR, CONFIGURED

processData(senderData, jsonData, agentConf, senderPyPath, senderPath, timeout, host)
link = r'https://github.com/nobodysu/zabbix-mini-IPMI/issues'
processData(senderData, jsonData, agentConf, senderPyPath, senderPath, timeout, host, link)
7 changes: 4 additions & 3 deletions mini_ipmi_smartctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import subprocess
import re
from shlex import split
from sender_wrapper import (readConfig, processData, replaceStr, pythonVer)
from sender_wrapper import (readConfig, processData, replaceStr, fail_ifNot_Py3)


def listDisks():
Expand Down Expand Up @@ -194,7 +194,7 @@ def getDisksTempSCT():


if __name__ == '__main__':
pythonVer()
fail_ifNot_Py3()

host = '"' + sys.argv[2] + '"'
jsonData = []
Expand Down Expand Up @@ -228,5 +228,6 @@ def getDisksTempSCT():
dR = replaceStr(d)
jsonData.append({'{#DISK}':dR}) # available disks must always be populated to LLD

processData(senderData, jsonData, agentConf, senderPyPath, senderPath, timeout, host)
link = r'https://github.com/nobodysu/zabbix-mini-IPMI/issues'
processData(senderData, jsonData, agentConf, senderPyPath, senderPath, timeout, host, link)

21 changes: 11 additions & 10 deletions sender_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def send():


# external
def pythonVer():
def fail_ifNot_Py3():
'''Terminate if not using python3.'''
if sys.version_info.major != 3:
sys.stdout.write(sys.argv[0] + ': Python3 is required.')
Expand Down Expand Up @@ -90,21 +90,21 @@ def readConfig(config):
print()


def processData(sender, json, conf, pyP, senderP, tout, hn):
def processData(sender, json, conf, pyP, senderP, tout, hn, issuesLink):
'''Compose data and try to send it.'''
try:
from subprocess import DEVNULL # for python versions greater than 3.3
from subprocess import DEVNULL # for python versions greater than 3.3, inclusive
except:
import os
DEVNULL = open(os.devnull, 'w') # for 3.0-3.2
DEVNULL = open(os.devnull, 'w') # for 3.0-3.2, inclusive

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

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

# spawn new process and regain shell control immediately (on Win 'mini-ipmi-send.py' will not wait)
# spawn new process and regain shell control immediately (on Win 'sender_wrapper.py' will not wait)
try:
subprocess.Popen([sys.executable, pyP, 'get', conf, senderP, tout, senderDataNStr], stdin=subprocess.PIPE, stdout=DEVNULL, stderr=DEVNULL)

Expand All @@ -123,7 +123,7 @@ def processData(sender, json, conf, pyP, senderP, tout, hn):

#for i in range(135000): senderDataNStr = senderDataNStr + '0' # HUGEDATA testing
try:
# do not detach if in verbose mode, also skips timeout in 'mini-ipmi-send.py'
# do not detach if in verbose mode, also skips timeout in 'sender_wrapper.py'
subprocess.Popen([sys.executable, pyP, 'getverb', conf, senderP, tout, senderDataNStr], stdin=subprocess.PIPE)

except OSError as e:
Expand All @@ -139,16 +139,17 @@ def processData(sender, json, conf, pyP, senderP, tout, hn):
raise

finally:
print(' Please report any issues to:\nhttps://github.com/nobodysu/zabbix-mini-IPMI/issues\n')
print(' Please report any issues or missing features to:\n%s\n' % issuesLink)

else:
print(sys.argv[0] + ": Not supported. Use 'get' or 'getverb'.")


def replaceStr(s):
'''Sanitizes provided string in correct order.'''
stopChars = (('/dev/', ''), (' -d', ''), ('!', '_'), (',', '_'), ('[', '_'),
(']', '_'), ('+', '_'), (' ', ' '), ('/', '_'), ('~', '_'),
stopChars = (('/dev/', ''), (' -d atacam', ''), (' -d scsi', ''), (' -d ata', ''), (' -d sat', ''), (' -d sas', ''), (' -d auto', ''),
(' -d', ''), ('!', '_'), (',', '_'), ('[', '_'), ('~', '_'),
(']', '_'), ('+', '_'), (' ', ' '), ('/', '_'), ('\\', '_'),
('`', '_'), ('@', '_'), ('#', '_'), ('$', '_'), ('%', '_'),
('^', '_'), ('&', '_'), ('*', '_'), ('(', '_'), (')', '_'),
('{', '_'), ('}', '_'), ('=', '_'), (':', '_'), (';', '_'),
Expand Down

0 comments on commit cd2b743

Please sign in to comment.