Skip to content

Commit

Permalink
CPU refactoring part 1 (#38)
Browse files Browse the repository at this point in the history
* dropping zabbix24 support
* switching to special OHMR which could exclude HDDs: openhardwaremonitor/openhardwaremonitor#1115
* disabling non-major triggers to reduce noise
* template tuning via user macro
* max vcore dropped
* max vtt dropped
* complex board and cpu-specific rules dropped
* ryzen support on linux
* fixes #19
* fixes #21
* fixes #29
* fixes #39
  • Loading branch information
nobodysu authored Dec 14, 2019
1 parent 1845fd8 commit e66ddea
Show file tree
Hide file tree
Showing 6 changed files with 1,101 additions and 947 deletions.
69 changes: 37 additions & 32 deletions BSD/mini_ipmi_bsdcpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

## Installation instructions: https://github.com/nobodysu/zabbix-mini-IPMI ##

binPath = r'/sbin/sysctl'
BIN_PATH = r'/sbin/sysctl'

# path to second send script
senderPyPath = r'/usr/local/etc/zabbix/scripts/sender_wrapper.py'
SENDER_WRAPPER_PATH = r'/usr/local/etc/zabbix/scripts/sender_wrapper.py'

# path to zabbix agent configuration file
agentConf = r'/usr/local/etc/zabbix3/zabbix_agentd.conf'
AGENT_CONF_PATH = r'/usr/local/etc/zabbix3/zabbix_agentd.conf'

senderPath = r'zabbix_sender'
#senderPath = r'/usr/bin/zabbix_sender'
SENDER_PATH = r'zabbix_sender'
#SENDER_PATH = r'/usr/bin/zabbix_sender'

timeout = '80' # how long the script must wait between LLD and sending, increase if data received late (does not affect windows)
TIMEOUT = '80' # 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
tjMax = '85'
TJMAX = '70'

## End of configuration ##

Expand All @@ -24,11 +24,14 @@
import re
from sender_wrapper import (readConfig, processData, fail_ifNot_Py3)

HOST = sys.argv[2]


def getOutput(binPath_):

def getOutput():
p = None
try:
p = subprocess.check_output([binPath, 'dev.cpu'], universal_newlines=True)
p = subprocess.check_output([binPath_, 'dev.cpu'], universal_newlines=True)
except OSError as e:
if e.args[0] == 2:
error = 'OS_NOCMD'
Expand All @@ -52,25 +55,25 @@ def getOutput():
return error, p


def getCpuData():
def getCpuData(pOut_):
'''Can work unexpectedly with multiple CPUs.'''
sender = []
json = []

temp = re.findall(r'dev\.cpu\.(\d+)\.temperature:\s+(\d+)', pOut, re.I)
if temp:
tempRe = re.findall(r'dev\.cpu\.(\d+)\.temperature:\s+(\d+)', pOut_, re.I)
if tempRe:
error = None
json.append({'{#CPU}':'0'})

allTemps = []
for i in temp:
allTemps.append(i[1])
sender.append('%s mini.cpu.temp[cpu0,core%s] "%s"' % (host, i[0], i[1]))
json.append({'{#CPUC}':'0', '{#CORE}':i[0]})
for num, val in tempRe:
allTemps.append(val)
sender.append('"%s" mini.cpu.temp[cpu0,core%s] "%s"' % (HOST, num, val))
json.append({'{#CPUC}':'0', '{#CORE}':num})

sender.append('%s mini.cpu.info[cpu0,TjMax] "%s"' % (host, tjMax))
sender.append('%s mini.cpu.temp[cpu0,MAX] "%s"' % (host, max(allTemps)))
sender.append('%s mini.cpu.temp[MAX] "%s"' % (host, max(allTemps)))
sender.append('"%s" mini.cpu.info[cpu0,TjMax] "%s"' % (HOST, TJMAX))
sender.append('"%s" mini.cpu.temp[cpu0,MAX] "%s"' % (HOST, max(allTemps)))
sender.append('"%s" mini.cpu.temp[MAX] "%s"' % (HOST, max(allTemps)))

else:
error = 'NOCPUTEMPS'
Expand All @@ -79,28 +82,30 @@ def getCpuData():


if __name__ == '__main__':

fail_ifNot_Py3()

host = '"' + sys.argv[2] + '"' # hostname
senderData = []
jsonData = []

getOutput_Out = getOutput()

statusC = None
if getOutput_Out[1]: # process output
pOut = getOutput_Out[1]
p_Output = getOutput(BIN_PATH)
pRunStatus = p_Output[0]
pOut = p_Output[1]

getCpuData_Out = getCpuData()
errors = None
if pOut:
getCpuData_Out = getCpuData(pOut)
cpuErrors = getCpuData_Out[2]
senderData.extend(getCpuData_Out[0])
jsonData.extend(getCpuData_Out[1])
if getCpuData_Out[2]:
statusC = 'cpu_err'
senderData.append('%s mini.cpu.info[ConfigStatus] "%s"' % (host, getCpuData_Out[2]))
if cpuErrors:
errors = 'cpu_err'
senderData.append('"%s" mini.cpu.info[ConfigStatus] "%s"' % (HOST, cpuErrors))

if not statusC:
senderData.append('%s mini.cpu.info[ConfigStatus] "%s"' % (host, getOutput_Out[0])) # OS_NOCMD, OS_ERROR, UNKNOWN_EXC_ERROR, CONFIGURED
if not errors:
senderData.append('"%s" mini.cpu.info[ConfigStatus] "%s"' % (HOST, pRunStatus)) # OS_NOCMD, OS_ERROR, UNKNOWN_EXC_ERROR, CONFIGURED

link = r'https://github.com/nobodysu/zabbix-mini-IPMI/issues'
processData(senderData, jsonData, agentConf, senderPyPath, senderPath, timeout, host, link)
sendStatusKey = 'mini.cpu.info[SendStatus]'
processData(senderData, jsonData, AGENT_CONF_PATH, SENDER_WRAPPER_PATH, SENDER_PATH, TIMEOUT, HOST, link, sendStatusKey)

7 changes: 3 additions & 4 deletions BSD/sudoers.d/zabbix
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Defaults:zabbix !requiretty
Cmnd_Alias ZABBIX_CMD = /usr/local/etc/zabbix/scripts/mini_ipmi_smartctl.py
#Defaults:zabbix !requiretty # Uncomment in case of sudo errors

zabbix ALL=NOPASSWD: /usr/local/etc/zabbix/scripts/mini_ipmi_smartctl.py

zabbix ALL = (other_user) NOPASSWD: ALL
zabbix ALL = (root) NOPASSWD: ZABBIX_CMD
Loading

0 comments on commit e66ddea

Please sign in to comment.