Ignore:
Timestamp:
Apr 8, 2018, 7:40:10 PM (6 years ago)
Author:
chronos
Message:
  • Added: New table NetworkDeviceLog to store log messages received from network devices.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Network/Network.php

    r849 r855  
    142142    $this->System->RegisterPage(array('network', 'frequency-plan'), 'PageFrequencyPlan');
    143143
     144    $this->System->RegisterCommandLine('config', array($this, 'ImportNetworkLog'));
     145
    144146    $this->System->FormManager->RegisterClass('NetworkDomainAlias', array(
    145147      'Title' => 'Alias domény',
     
    178180        'LoginPassword' => array('Type' => 'String', 'Caption' => 'Přihlašovací heslo', 'Default' => '', 'Null' => true, 'NotInList' => true),
    179181        'API' => array('Type' => 'TDeviceAPIType', 'Caption' => 'API', 'Default' => '', 'Null' => true),
     182        'Logs' => array('Type' => 'TDeviceLogList', 'Caption' => 'Záznamy', 'Default' => ''),
    180183      ),
    181184      'AfterInsert' => array($this, 'AfterInsertNetworkDevice'),
     
    190193        'ShowOnline' => array('Type' => 'Boolean', 'Caption' => 'Ukázat online', 'Default' => '0'),
    191194        'IconName' => array('Type' => 'String', 'Caption' => 'Jméno ikony', 'Default' => '0'),
     195      ),
     196    ));
     197    $this->System->FormManager->RegisterClass('NetworkDeviceLog', array(
     198      'Title' => 'Zprávy zařízení',
     199      'Table' => 'NetworkDeviceLog',
     200      'DefaultSortColumn' => 'Time',
     201      'DefaultSortOrder' => 1,
     202      'Items' => array(
     203        'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => ''),
     204        'Device' => array('Type' => 'TNetworkDevice', 'Caption' => 'Zařízení', 'Default' => ''),
     205        'Message' => array('Type' => 'String', 'Caption' => 'Zpáva', 'Default' => ''),
     206        'Tags' => array('Type' => 'String', 'Caption' => 'Značky', 'Default' => ''),
    192207      ),
    193208    ));
     
    650665      'Filter' => '1',
    651666    ));
     667    $this->System->FormManager->RegisterFormType('TDeviceLogList', array(
     668      'Type' => 'ManyToOne',
     669      'Table' => 'NetworkDeviceLog',
     670      'Id' => 'Id',
     671      'Ref' => 'Device',
     672      'Filter' => '1',
     673    ));
    652674    $this->System->FormManager->RegisterFormType('TNetworkLinkListInterface', array(
    653675      'Type' => 'ManyToOne',
     
    725747    $this->Database->query('DELETE FROM `NetworkInterfaceWireless` WHERE `NetworkInterface`='.$Id);
    726748    $this->Database->query('DELETE FROM `NetworkInterfaceLatency` WHERE `Interface`='.$Id);
     749  }
     750 
     751  function ImportNetworkLog($Parameters)
     752  {
     753    global $Config;
     754   
     755    $DbResult = $this->System->Database->select('NetworkDeviceLog', 'Time',
     756      '1 ORDER BY Time DESC LIMIT 1');
     757    if ($DbResult->num_rows > 0)
     758    {
     759      $DbRow = $DbResult->fetch_assoc();
     760      $WhereTime = ' AND (`Time` > "'.$DbRow['Time'].'")';
     761    } else $WhereTime = '';
     762
     763    $RemoteDb = new Database();
     764    $RemoteDb->Connect($Config['NetworkLog']['Host'], $Config['NetworkLog']['User'],
     765      $Config['NetworkLog']['Password'], $Config['NetworkLog']['Database']);
     766    $DbResult = $RemoteDb->select('SystemEvents', '*', '`ReceivedAt`>"'. TimeToMysqlDate($StartTime).'"'.$WhereTime.' ORDER BY `Time` DESC');
     767    while ($DbRow = $DbResult->fetch_array())
     768    {
     769      $DbResult2 = $this->System->Database->select('NetworkInterface', 'Device, CONCAT(CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")), ".") AS `Name` ', '`Name` LIKE "'.$DbRow['FromHost'].'"');
     770      if ($DbResult2->num_rows > 0)             
     771      {
     772        $DbRow2 = $DbResult2->fetch_assoc();
     773        $DeviceID = $DbRow2['Device'];
     774        $this->System->Database->insert('NetworkDeviceLog', array('Time' => $DbRow['ReceivedAt'],
     775          'Device' => $DeviceId, 'Message' => $DbRow['Message'], 'Tags' => $DbRow['SysLogTag']));
     776      } else echo('Host '.$DbRow['Host'].' not paired with network device.'."\n");
     777    }
    727778  }
    728779
Note: See TracChangeset for help on using the changeset viewer.