diff --git a/src/modbus.c b/src/modbus.c index 994f9b3..74ce28c 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -212,7 +212,12 @@ int zbx_modbus_read_registers(AGENT_REQUEST *request, AGENT_RESULT *result) modbus_free(ctx); return SYSINFO_RET_FAIL; } - modbus_set_slave(ctx, slave_id); + if (modbus_set_slave(ctx, slave_id) == -1) + { + SET_MSG_RESULT(result, strdup("Check slaveid parameter")); + modbus_free(ctx); + return SYSINFO_RET_FAIL; + } // set register to start from errno = 0; diff --git a/tests/test_01modbus_errors.py b/tests/test_01modbus_errors.py index 4d1df75..a0508ec 100644 --- a/tests/test_01modbus_errors.py +++ b/tests/test_01modbus_errors.py @@ -63,7 +63,7 @@ def test_bad_register_string(self, host): def test_bad_slaveid_integer(self, host): key = "modbus_read_registers["+host+",5000,99,3,uint32,BE,0]" - assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Illegal data address' + assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Check slaveid parameter' def test_bad_slaveid_string(self, host): key = "modbus_read_registers["+host+",bad,1,3,uint32,BE,0]" - assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Check slaveid parameter' + assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Check slaveid parameter'