Example #1
0
 /**
  * Update switch's details using SNMP polling
  *
  * @throws \OSS_SNMP\Exception
  * @see self::$OSS_SNMP_SWITCH_ELEMENTS
  *
  * @param \OSS_SNMP\SNMP $host An instance of \OSS_SNMP\SNMP for this switch
  * @param \OSS_Logger $logger An instance of the logger or false
  * @return \Entities\Switcher For fluent interfaces
  */
 public function snmpPoll($host, $logger = false)
 {
     // utility to format dates
     $formatDate = function ($d) {
         return $d instanceof \DateTime ? $d->format('Y-m-d H:i:s') : 'Unknown';
     };
     foreach (self::$OSS_SNMP_SWITCH_ELEMENTS as $p) {
         $fn = "get{$p}";
         $n = $host->getPlatform()->{$fn}();
         if ($logger) {
             switch ($p) {
                 case 'OsDate':
                     if ($formatDate($this->{$fn}()) != $formatDate($n)) {
                         $logger->info(" [{$this->getName()}] Platform: Updating {$p} from " . $formatDate($this->{$fn}()) . " to " . $formatDate($n));
                     } else {
                         $logger->info(" [{$this->getName()}] Platform: Found {$p}: " . $formatDate($n));
                     }
                     break;
                 default:
                     if ($logger && $this->{$fn}() != $n) {
                         $logger->info(" [{$this->getName()}] Platform: Updating {$p} from {$this->{$fn}()} to {$n}");
                     } else {
                         $logger->info(" [{$this->getName()}] Platform: Found {$p}: {$n}");
                     }
                     break;
             }
         }
         $fn = "set{$p}";
         $this->{$fn}($n);
     }
     // does this switch support the IANA MAU MIB?
     try {
         $host->useMAU()->types();
         $this->setMauSupported(true);
     } catch (\OSS_SNMP\Exception $e) {
         $this->setMauSupported(false);
     }
     $this->setLastPolled(new \DateTime());
     return $this;
 }