Logic Machine Forum
SNMP for UPS SHTYL (SW250/SW500/SW1000) - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: SNMP for UPS SHTYL (SW250/SW500/SW1000) (/showthread.php?tid=3214)



SNMP for UPS SHTYL (SW250/SW500/SW1000) - m.j.sorokin - 10.03.2021

Code:
--UPS SHTYL (SW250/SW500/SW1000)
--IC-SNMP/Web
--MIB (https://www.shtyl.ru/upload/iblock/74f/Shtyl_MIB_UPS2_06.mib)

ups_ip = "192.168.0.1"

Connection_status = "1/6/25"

DataUPS = {}
DataUPS[1] = {oid=".1.3.6.1.2.1.33.1.2.1.0", knx_grop="1/6/26", dtype=5}
-- upsBatteryStatus{unknown(1),batteryNormal(2),batteryLow(3),batteryDepleted(4)}

DataUPS[2] = {oid=".1.3.6.1.2.1.33.1.2.2.0", knx_grop="1/6/27", dtype=99}
-- upsSecondsOnBattery --(Datatype 9, value Hours.minutes)

DataUPS[3] = {oid=".1.3.6.1.2.1.33.1.2.3.0", knx_grop="1/6/28", dtype=7}
-- upsEstimatedMinutesRemaining

DataUPS[4] = {oid=".1.3.6.1.2.1.33.1.2.4.0", knx_grop="1/6/29", dtype=7}
-- upsEstimatedChargeRemaining

DataUPS[5] = {oid=".1.3.6.1.2.1.33.1.2.5.0", knx_grop="1/6/30", dtype=9}
-- upsBatteryVoltage

DataUPS[6] = {oid=".1.3.6.1.2.1.33.1.2.6.0", knx_grop="1/6/31", dtype=9}
-- upsBatteryCurrent

DataUPS[7] = {oid=".1.3.6.1.2.1.33.1.2.7.0", knx_grop="1/6/32", dtype=7}
-- upsBatteryTemperature

DataUPS[8] = {oid=".1.3.6.1.2.1.33.1.3.3.1.2.1", knx_grop="1/6/33", dtype=9}
-- upsInputFrequency

DataUPS[9] = {oid=".1.3.6.1.2.1.33.1.3.3.1.3.1", knx_grop="1/6/34", dtype=7}
-- upsInputVoltage

DataUPS[10] = {oid=".1.3.6.1.2.1.33.1.3.3.1.4.1", knx_grop="1/6/35", dtype=9}
-- upsInputCurrent

DataUPS[11] = {oid=".1.3.6.1.2.1.33.1.4.1.0", knx_grop="1/6/36", dtype=5}
-- upsOutputSource {other(1),none(2),normal(3),bypass(4),battery(5),booster(6),reducer(7)}

DataUPS[12] = {oid=".1.3.6.1.2.1.33.1.4.2.0", knx_grop="1/6/37", dtype=9}
-- upsOutputFrequency

DataUPS[13] = {oid=".1.3.6.1.2.1.33.1.4.4.1.2.1", knx_grop="1/6/38", dtype=7}
-- upsOutputVoltage

DataUPS[14] = {oid=".1.3.6.1.2.1.33.1.4.4.1.3.1", knx_grop="1/6/39", dtype=9}
-- upsOutputCurrent

DataUPS[15] = {oid=".1.3.6.1.2.1.33.1.4.4.1.5.1", knx_grop="1/6/40", dtype=7}
-- upsOutputPercentLoad

DataUPS[16] = {oid=".1.3.6.1.2.1.33.1.5.1.0", knx_grop="1/6/41", dtype=9}
-- upsBypassFrequency

DataUPS[17] = {oid=".1.3.6.1.2.1.33.1.5.3.1.2.1", knx_grop="1/6/42", dtype=7}
-- upsBypassVoltage

DataUPS[18] = {oid=".1.3.6.1.2.1.33.1.5.3.1.3.1", knx_grop="1/6/43", dtype=9}
-- upsBypassCurrent

DataUPS[19] = {oid=".1.3.6.1.2.1.33.1.6.1", knx_grop="1/6/44", dtype=1}
-- upsAlarmsPresent

--oid=".1.3.6.1.2.1.33.1.3.3.1.5.1" -- upsInputTruePower
--oid=".1.3.6.1.2.1.33.1.4.4.1.4.1" -- upsOutputPower
--oid=".1.3.6.1.2.1.33.1.5.3.1.4.1" -- upsBypassPower

require "snmp"

local mib, err = snmp.mib.load('/home/ftp/snmp/UPS-MIB.mib')
if not mib then
   --log('Failed to load mib: ' .. err)
end

ups1, err = snmp.open{
  version = snmp.SNMPv2,
  community = "public",
  port = 161,
  peer = ups_ip,
}

if ups1 then

grp.checkwrite(Connection_status, 1)   
 
for i=1,19 do  
  vbind, err = ups1:get(DataUPS[i].oid)

  if (vbind.value ~= nil) then
    res = vbind.value
  end

  if ((DataUPS[i].dtype == 9) and (i~=5)) then res = res * 0.1 end

  if i == 2 then
    hour = vbind.value/60
    hour = math.floor(hour)
    min = vbind.value%60
    res=hour+(min*0.01)
  end

  if i == 19 then
    if res ~= 0 then res = 1 end
  end

  grp.checkwrite(DataUPS[i].knx_grop, res)

end
 
else
  grp.checkwrite(Connection_status, 0)
end 

ups1:close()