/** * get Logger * * @return OSS_Log */ public function getLogger() { if (null === $this->_logger) { // Get Doctrine configuration options from the application.ini file $options = $this->getOptions(); $logger = new OSS_Log(); if (isset($options['enabled']) && $options['enabled']) { foreach ($options['writers'] as $writer => $writerOptions) { switch ($writer) { case 'stream': if (isset($writerOptions['mode']) && ($writerOptions['mode'] = 'single')) { $log_path = $writerOptions['path']; $log_file = $log_path . DIRECTORY_SEPARATOR . (isset($writerOptions['logname']) ? $writerOptions['logname'] : 'log.log'); } else { $log_path = $writerOptions['path'] . DIRECTORY_SEPARATOR . date('Y') . DIRECTORY_SEPARATOR . date('m'); $log_file = $log_path . DIRECTORY_SEPARATOR . date('Ymd') . '.log'; } if (file_exists($log_path) == false) { mkdir($log_path, 0755, true); @chmod($log_path, 0755); @chown($log_path, $writerOptions['owner']); @chgrp($log_path, $writerOptions['group']); } if (file_exists($log_file) == false) { touch($log_file); @chmod($log_file, 0777); @chown($log_file, $writerOptions['owner']); @chgrp($log_file, $writerOptions['group']); } $streamWriter = new Zend_Log_Writer_Stream($log_file); $streamWriter->setFormatter(new Zend_Log_Formatter_Simple('%timestamp% %priorityName% (%priority%) ' . (isset($_SERVER['REMOTE_ADDR']) == true ? "[{$_SERVER['REMOTE_ADDR']}]" : "") . ': %message%' . PHP_EOL)); $logger->addWriter($streamWriter); if (isset($writerOptions['level'])) { $logger->addFilter((int) $writerOptions['level']); } break; case 'email': $mail = new Zend_Mail(); $mail->setFrom($writerOptions['from'])->addTo($writerOptions['to']); $mailWriter = new Zend_Log_Writer_Mail($mail); // Set subject text for use; summary of number of errors is appended to the // subject line before sending the message. $mailWriter->setSubjectPrependText("[{$writerOptions['prefix']}]"); // Only email entries with level requested and higher. $mailWriter->addFilter((int) $writerOptions['level']); $logger->addWriter($mailWriter); break; case 'firebug': if ($writerOptions['enabled']) { $firebugWriter = new Zend_Log_Writer_Firebug(); $firebugWriter->addFilter((int) $writerOptions['level']); $logger->addWriter($firebugWriter); } break; default: try { $logger->log("Unknown log writer: {$writer}", Zend_Log::WARN); } catch (Zend_Log_Exception $e) { die("Unknown log writer [{$writer}] during application bootstrap"); } break; } } } else { $logger->addWriter(new Zend_Log_Writer_Null()); } try { $logger->debug('Logger instantiated', Zend_Log::INFO); } catch (Zend_Log_Exception $e) { die("Unknown log writer [{$writer}] during application bootstrap"); } $this->_logger = $logger; } return $this->_logger; }
/** * Poll and update switch objects via SNMP */ public function snmpPollAction() { $sws = []; // have we been given a specific switch? if ($this->getParam('switch', false)) { if ($sw = $this->getD2R('\\Entities\\Switcher')->findOneBy(['name' => $this->getParam('switch')])) { $sws[] = $sw; } else { echo "ERR: No switch found with name " . $this->getParam('switch') . "\n"; return; } } else { // find all active switches $sws = $this->getD2R('\\Entities\\Switcher')->getActive(); } if (count($sws)) { // create a logger for stdout if ($this->isVerbose() || $this->isDebug()) { $writer = new Zend_Log_Writer_Stream('php://output'); $logger = new OSS_Log(); if (!$this->isDebug()) { } $logger->addFilter(new Zend_Log_Filter_Priority(OSS_Log::INFO)); $logger->addWriter($writer); } else { $logger = false; } foreach ($sws as $sw) { if (trim($sw->getSnmppasswd()) == '') { $this->verbose("Skipping {$sw->getName()} as no SNMP password set"); continue; } if ($sw->getLastPolled() == null) { echo "First time polling of {$sw->getName()} with SNMP request to {$sw->getHostname()}\n"; } else { $this->verbose("Polling {$sw->getName()} with SNMP request to {$sw->getHostname()}"); } $swPolled = false; try { $swPolled = false; $host = new \OSS_SNMP\SNMP($sw->getHostname(), $sw->getSnmppasswd()); $sw->snmpPoll($host, $logger); $swPolled = true; if ($sw->getSwitchtype() == \Entities\Switcher::TYPE_SWITCH) { $sw->snmpPollSwitchPorts($host, $logger); } if ($this->getParam('noflush', false)) { $this->verbose('*** noflush parameter set - NO CHANGES MADE TO DATABASE'); } else { $this->getD2EM()->flush(); } } catch (\OSS_SNMP\Exception $e) { if ($swPolled) { echo "ERROR: OSS_SNMP exception polling {$sw->getName()} by SNMP\n"; } else { echo "ERROR: OSS_SNMP exception polling ports for {$sw->getName()} by SNMP\n"; } } } } }