Changeset 855


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.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UpdateTrace.php

    r844 r855  
    20412041{
    20422042  $Manager->Execute('ALTER TABLE `DocumentLine` ADD `Yearly` BOOLEAN NOT NULL DEFAULT FALSE AFTER `Shortcut`;');
     2043}
     2044
     2045function UpdateTo855($Manager)
     2046{
     2047  $Manager->Execute('CREATE TABLE IF NOT EXISTS `NetworkDeviceLog` (
     2048    `Id` int(11) NOT NULL AUTO_INCREMENT,
     2049    `Time` datetime NOT NULL,
     2050    `Device` int(11) NOT NULL,
     2051    `Message` varchar(255) NOT NULL,
     2052    `Tags` varchar(255) NOT NULL,
     2053    PRIMARY KEY (`Id`),
     2054    KEY `Device` (`Device`)
     2055    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
     2056  $Manager->Execute('ALTER TABLE `NetworkDeviceLog`
     2057    ADD CONSTRAINT `NetworkDeviceLog_ibfk_1` FOREIGN KEY (`Device`) REFERENCES `NetworkDevice` (`Id`);');
    20432058}
    20442059
     
    21382153      831 => array('Revision' => 838, 'Function' => 'UpdateTo838'),
    21392154      838 => array('Revision' => 844, 'Function' => 'UpdateTo844'),
     2155      844 => array('Revision' => 855, 'Function' => 'UpdateTo855'),
    21402156    ));
    21412157  }
  • trunk/Application/Version.php

    r849 r855  
    11<?php
    22
    3 $Revision = 849; // Subversion revision
    4 $DatabaseRevision = 844; // SQL structure revision
    5 $ReleaseTime = strtotime('2017-09-05');
     3$Revision = 855; // Subversion revision
     4$DatabaseRevision = 855; // SQL structure revision
     5$ReleaseTime = strtotime('2018-04-08');
  • 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.