Skip to content

Commit

Permalink
Improving security and updating paths (#66)
Browse files Browse the repository at this point in the history
* narrowing sudo to smartctl only

* proper smartctl path on FreeBSD

* rename include folder
  • Loading branch information
nobody43 authored Feb 27, 2023
1 parent 0e34752 commit a458a2c
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 40 deletions.
6 changes: 3 additions & 3 deletions BSD/mini_ipmi_bsdcpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
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)
# this setting MUST be lower than 'Update interval' in discovery rule
DELAY = '50' # 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 = '70'

## End of configuration ##
Expand Down Expand Up @@ -107,5 +107,5 @@ def getCpuData(pOut_):

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

4 changes: 2 additions & 2 deletions BSD/sudoers.d/zabbix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Defaults:zabbix !requiretty # Uncomment in case of sudo errors
#Defaults:zabbix !requiretty # Older sudo

zabbix ALL=NOPASSWD: /usr/local/etc/zabbix/scripts/mini_ipmi_smartctl.py
zabbix ALL=NOPASSWD: /usr/sbin/smartctl, /usr/bin/smartctl, /usr/local/sbin/smartctl, /sbin/smartctl, /bin/smartctl

5 changes: 2 additions & 3 deletions BSD/zabbix_agentd.conf.d/userparameter_mini-ipmi2.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
UserParameter=mini.disktemp.discovery[*], PATH=/usr/local/sbin:/usr/local/bin sudo "/usr/local/etc/zabbix/scripts/mini_ipmi_smartctl.py" "$1" "$2"
UserParameter=mini.cputemp.discovery[*], PATH=/usr/local/sbin:/usr/local/bin "/usr/local/etc/zabbix/scripts/mini_ipmi_bsdcpu.py" "$1" "$2"

UserParameter=mini.disktemp.discovery[*], PATH=/usr/local/sbin:/usr/local/bin "/usr/local/etc/zabbix/scripts/mini_ipmi_smartctl.py" "$1" "$2"
UserParameter=mini.cputemp.discovery[*], PATH=/usr/local/sbin:/usr/local/bin "/usr/local/etc/zabbix/scripts/mini_ipmi_bsdcpu.py" "$1" "$2"
6 changes: 3 additions & 3 deletions Linux/mini_ipmi_lmsensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
('k\d+temp-pci-\w+\nAdapter:\s+PCI\s+adapter\ntemp(\d+):\n\s+temp\d+_input:\s+(\d+)'),
)

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
DELAY = '50' # 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

## End of configuration ##

Expand Down Expand Up @@ -310,5 +310,5 @@ def getCpuData(pOut_):

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

4 changes: 2 additions & 2 deletions Linux/sudoers.d/zabbix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Defaults:zabbix !requiretty # Uncomment in case of sudo errors
#Defaults:zabbix !requiretty # Older sudo

zabbix ALL=NOPASSWD: /etc/zabbix/scripts/mini_ipmi_smartctl.py
zabbix ALL=NOPASSWD: /usr/sbin/smartctl, /usr/bin/smartctl, /usr/local/sbin/smartctl, /sbin/smartctl, /bin/smartctl

4 changes: 2 additions & 2 deletions Linux/zabbix_agentd.d/userparameter_mini-ipmi2.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
UserParameter=mini.disktemp.discovery[*], sudo "/etc/zabbix/scripts/mini_ipmi_smartctl.py" "$1" "$2"
UserParameter=mini.cputemp.discovery[*], "/etc/zabbix/scripts/mini_ipmi_lmsensors.py" "$1" "$2"
UserParameter=mini.disktemp.discovery[*], "/etc/zabbix/scripts/mini_ipmi_smartctl.py" "$1" "$2"
UserParameter=mini.cputemp.discovery[*], "/etc/zabbix/scripts/mini_ipmi_lmsensors.py" "$1" "$2"
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ Verbose mode. Does not detaches or prints LLD. Lists all items sent to zabbix-se
<br /><br />

These scripts were tested to work with following configurations:
- Debian 11 / Server (5.0, 6.0) / Agent 4.0 / Python 3.9
- Ubuntu 22.04 / Server (5.0, 6.0) / Agent 5.0 / Python 3.10
- Windows Server 2012 / Server 6.0 / Agent 4.0 / Python (3.7, 3.11)
- Windows 10 / Server 6.0 / Agent 4.0 / Python (3.10, 3.11)
- Windows 7 / Server 6.0 / Agent 4.0 / Python (3.4, 3.7, 3.8)
- Centos 7 / Zabbix 3.0 / Python 3.6
- Debian 9 / Zabbix 3.0 / Python 3.5
- Debian 10 / Server 5.0 / Agent 4.0 / Python 3.7
- Ubuntu 20.04 / Server 5.0 / Agent 4.0 / Python 3.8
- FreeBSD 10.3 / Zabbix 3.0 / Python 3.6
- Windows XP / Zabbix 3.0 / Python 3.4
- Windows 7 / Zabbix (3.0, 5.0) / Python (3.4, 3.7, 3.8)
- Windows Server 2012 / Zabbix 3.0 / Python 3.7

## Known issues
- Zabbix web panel displays an error on json discovery, but everything works fine ([#18](https://github.com/nobodysu/zabbix-mini-IPMI/issues/18))
Expand Down
14 changes: 7 additions & 7 deletions Win/mini_ipmi_ohmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
## Installation instructions: https://github.com/nobodysu/zabbix-mini-IPMI ##

#BIN_PATH = r'OpenHardwareMonitorReport.exe'
BIN_PATH = r'C:\distr\OpenHardwareMonitorReport\OpenHardwareMonitorReport.exe' # if OHMR isn't in PATH
BIN_PATH = r'C:\Program Files\OpenHardwareMonitorReport\OpenHardwareMonitorReport.exe' # if OHMR isn't in PATH

# path to send script
SENDER_WRAPPER_PATH = r'C:\zabbix-agent\scripts\sender_wrapper.py'
SENDER_WRAPPER_PATH = r'C:\Program Files\Zabbix Agent\scripts\sender_wrapper.py'

# path to zabbix agent configuration file
AGENT_CONF_PATH = r'C:\zabbix_agentd.conf'
AGENT_CONF_PATH = r'C:\Program Files\Zabbix Agent\zabbix_agentd.conf'

#SENDER_PATH = r'zabbix_sender'
SENDER_PATH = r'C:\zabbix-agent\bin\win32\zabbix_sender.exe'
SENDER_PATH = r'C:\Program Files\Zabbix Agent\zabbix_sender.exe'

PARAMS = 'reporttoconsole --IgnoreMonitorHDD --IgnoreMonitorRAM'
# Possible params:
Expand Down Expand Up @@ -62,8 +62,8 @@
('^VTT$', 'VTT', '{#VTT}'),
)

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
DELAY = '50' # 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

## End of configuration ##

Expand Down Expand Up @@ -475,5 +475,5 @@ def getGpusData(pOut_):

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

2 changes: 0 additions & 2 deletions Win/zabbix_agentd.conf.d/userparameter_mini-ipmi2.conf

This file was deleted.

2 changes: 2 additions & 0 deletions Win/zabbix_agentd.d/userparameter_mini-ipmi2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UserParameter=mini.disktemp.discovery[*], python "C:\Program Files\Zabbix Agent\scripts\mini_ipmi_smartctl.py" "$1" "$2"
UserParameter=mini.cputemp.discovery[*], python "C:\Program Files\Zabbix Agent\scripts\mini_ipmi_ohmr.py" "$1" "$2"
33 changes: 22 additions & 11 deletions mini_ipmi_smartctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

# path to zabbix agent configuration file
agentConf_LINUX = r'/etc/zabbix/zabbix_agentd.conf'
agentConf_WIN = r'C:\zabbix_agentd.conf'
agentConf_WIN = r'C:\Program Files\Zabbix Agent\zabbix_agentd.conf'
agentConf_OTHER = r'/usr/local/etc/zabbix3/zabbix_agentd.conf'

senderPath_LINUX = r'zabbix_sender'
senderPath_WIN = r'C:\zabbix-agent\bin\win32\zabbix_sender.exe'
senderPath_WIN = r'C:\Program Files\Zabbix Agent\zabbix_sender.exe'
senderPath_OTHER = r'/usr/local/bin/zabbix_sender'

# path to second send script
senderPyPath_LINUX = r'/etc/zabbix/scripts/sender_wrapper.py'
senderPyPath_WIN = r'C:\zabbix-agent\scripts\sender_wrapper.py'
senderPyPath_WIN = r'C:\Program Files\Zabbix Agent\scripts\sender_wrapper.py'
senderPyPath_OTHER = r'/usr/local/etc/zabbix/scripts/sender_wrapper.py'


Expand All @@ -37,8 +37,8 @@

perDiskTimeout = 3 # Single disk query can not exceed this value. Python33 or above required.

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.
delay = '50' # 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 @@ -50,6 +50,7 @@
noTemperatureSensorModels = (
'INTEL SSDSC2CW060A3',
'AXXROMBSASMR',
'PLEXTOR PX-256M6Pro',
)

# re.IGNORECASE | re.MULTILINE
Expand Down Expand Up @@ -83,9 +84,9 @@
def scanDisks(mode):
'''Determines available disks. Can be skipped.'''
if mode == 'NOTYPE':
cmd = [binPath, '--scan']
cmd = addSudoIfNix([binPath, '--scan'])
elif mode == 'NVME':
cmd = [binPath, '--scan', '-d', 'nvme']
cmd = addSudoIfNix([binPath, '--scan', '-d', 'nvme'])
else:
print('Invalid type %s. Terminating.' % mode)
sys.exit(1)
Expand Down Expand Up @@ -171,7 +172,7 @@ def findErrorsAndOuts(cD):
p = ''

try:
cmd = [binPath, '-A', '-i', '-n', 'standby'] + shlex.split(cD)
cmd = addSudoIfNix([binPath, '-A', '-i', '-n', 'standby']) + shlex.split(cD)

if (sys.version_info.major == 3 and
sys.version_info.minor <= 2):
Expand Down Expand Up @@ -250,6 +251,7 @@ def findSerial(p):


def chooseSystemSpecificPaths():

if sys.platform.startswith('linux'):
binPath_ = binPath_LINUX
agentConf_ = agentConf_LINUX
Expand Down Expand Up @@ -286,8 +288,8 @@ def isModelWithoutSensor(p):
break

return result


def isDummyNVMe(p):
subsystemRe = re.search(r'Subsystem ID:\s+0x0000', p, re.I)
ouiRe = re.search(r'IEEE OUI Identifier:\s+0x000000', p, re.I)
Expand All @@ -300,6 +302,15 @@ def isDummyNVMe(p):
return False


def addSudoIfNix(cmd):

result = cmd
if not sys.platform == 'win32':
result = ['sudo'] + cmd

return result


if __name__ == '__main__':
fail_ifNot_Py3()

Expand Down Expand Up @@ -399,5 +410,5 @@ def isDummyNVMe(p):

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

0 comments on commit a458a2c

Please sign in to comment.