Exemple #1
0
 private function parseSysLog()
 {
     /*
      * For parsing the syslog looking for sensord entries
      * POTENTIALLY BUGGY -- only tested on debian/ubuntu flavored syslogs
      * Also slow as balls as it parses the entire syslog instead of
      * using something like tail
      */
     $file = '/var/log/syslog';
     if (!is_file($file) || !is_readable($file)) {
         return array();
     }
     $devices = array();
     foreach (Common::getLines($file) as $line) {
         if (preg_match('/\\w+\\s*\\d+ \\d{2}:\\d{2}:\\d{2} \\w+ sensord:\\s*(.+):\\s*(.+)/i', trim($line), $match) == 1) {
             // Replace current record of dev with updated temp
             $devices[$match[1]] = $match[2];
         }
     }
     $return = array();
     foreach ($devices as $dev => $stat) {
         $return[] = array('path' => 'N/A', 'name' => $dev, 'temp' => $stat, 'unit' => '');
     }
     return $return;
 }
Exemple #2
0
 /**
  * Do the job.
  */
 public function work()
 {
     $t = new Timer('dnsmasq leases extension');
     foreach (Common::getLines($this->_leases_file) as $line) {
         if (!preg_match('/^(\\d+) ([a-z0-9:]+) (\\S+) (\\S+)/', $line, $m)) {
             continue;
         }
         $this->_leases[] = array_combine(array('lease_end', 'mac', 'ip', 'hostname'), array_slice($m, 1));
     }
 }
Exemple #3
0
 private function _call()
 {
     $this->_res = array();
     foreach ($this->_servers as $name => $path) {
         $lines = Common::getLines($path);
         if (count($lines) == 0) {
             continue;
         }
         $info = self::readgamestat($lines);
         $this->_res[] = array('name' => $name, 'info' => $info);
     }
 }
Exemple #4
0
 /**
  * @test
  */
 public function getLines()
 {
     $lines = array("lineone\n", "linetwo\n", "line3\n");
     $file = LINFO_TESTDIR . '/files/lines.txt';
     $this->assertEquals($lines, Common::getLines($file));
 }
Exemple #5
0
 private function parseSysLogData()
 {
     $file = '/var/log/syslog';
     if (!is_file($file) || !is_readable($file)) {
         return array();
     }
     $devices = array();
     foreach (Common::getLines($file) as $line) {
         if (preg_match('/\\w+\\s*\\d+ \\d{2}:\\d{2}:\\d{2} \\w+ hddtemp\\[\\d+\\]: (.+): (.+): (\\d+) ([CF])/i', trim($line), $match) == 1) {
             // Replace current record of dev with updated temp
             $devices[$match[1]] = array($match[2], $match[3], $match[4]);
         }
     }
     $return = array();
     foreach ($devices as $dev => $stat) {
         $return[] = array('path' => $dev, 'name' => $stat[0], 'temp' => $stat[1], 'unit' => strtoupper($stat[2]));
     }
     return $return;
 }