<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage discovery
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */

echo(" HWG-PWR-MIB ");

/**
  STE-MIB::sensIndex.1 = INTEGER: 26518
  STE-MIB::sensIndex.2 = INTEGER: 29068
  STE-MIB::sensName.1 = STRING: "Sensor 26518"
  STE-MIB::sensName.2 = STRING: "Sensor 29068"
  STE-MIB::sensState.1 = INTEGER: normal(1)
  STE-MIB::sensState.2 = INTEGER: alarmlo(4)
  STE-MIB::sensString.1 = STRING: "19.6"
  STE-MIB::sensString.2 = STRING: "26.1"
  STE-MIB::sensValue.1 = INTEGER: 196
  STE-MIB::sensValue.2 = INTEGER: 261
  STE-MIB::sensSN.1 = STRING: "289667F30100000F"
  STE-MIB::sensSN.2 = STRING: "268C71130100004D"
  STE-MIB::sensUnit.1 = INTEGER: celsius(1)
  STE-MIB::sensUnit.2 = INTEGER: percent(4)
  STE-MIB::sensID.1 = INTEGER: 26518
  STE-MIB::sensID.2 = INTEGER: 29068
 */

$oids = snmpwalk_cache_multi_oid($device, "mtvalTableValues", array(), "HWG-PWR-MIB", mib_dirs('hwgroup'));

foreach ($oids as $index => $entry)
{
  $oid   = ".1.3.6.1.4.1.21796.4.6.1.3.1.6.$index";
  $descr = $entry['mtvalName'];
  $value = $entry['mtvalMbusValue'];
  $scale = pow(10, $entry['mtvalExp']);

  // sensUnit: none (0), celsius (1), fahrenheit (2), kelvin (3), percent(4)
  switch ($entry['mtvalUnit'])
  {
    case 'A':
      $type = 'current';
      break;
    case 'V':
      $type = 'voltage';
      break;
    case 'W':
      $type = 'power';
      break;
    case 'kWh':
      $type = 'energy';
      break;
    default:
      continue 2; // continue foreach loop
  }

  if (is_numeric($value))
  {
      discover_sensor($valid['sensor'], $type, $device, $oid, "mtvalEntry.$index", 'hwgpwr', $descr, $scale, $value);
  }
}

// EOF
