Changeset 867


Ignore:
Timestamp:
Jan 13, 2020, 12:26:00 AM (5 years ago)
Author:
chronos
Message:
  • Added: NotifLog table to collect notify changes in table to be able to preset them through RSS channel.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UpdateTrace.php

    r862 r867  
    20632063  $Manager->Execute('ALTER TABLE `NetworkInterfaceUpDown` ADD INDEX ( `Previous` )');
    20642064  $Manager->Execute('UPDATE `NetworkInterfaceUpDown` AS T1, `NetworkInterfaceUpDown` AS T2 SET T1.Previous = T2.Id WHERE (T1.Previous IS NULL) AND (T2.Interface=T1.Interface) AND (T1.Time = DATE_ADD(T2.Time, INTERVAL T2.Duration SECOND))');
     2065}
     2066
     2067function UpdateTo867($Manager)
     2068{
     2069  $Manager->Execute('CREATE TABLE IF NOT EXISTS `NotifyLog` (
     2070    `Id` int(11) NOT NULL AUTO_INCREMENT,
     2071    `Time` datetime NOT NULL,
     2072    `Title` varchar(255) NOT NULL DEFAULT "",
     2073    `Content` mediumtext NOT NULL DEFAULT "",
     2074    PRIMARY KEY (`Id`),
     2075    KEY `Time` (`Time`)
     2076  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
     2077
    20652078}
    20662079
     
    21622175      844 => array('Revision' => 855, 'Function' => 'UpdateTo855'),
    21632176      855 => array('Revision' => 862, 'Function' => 'UpdateTo862'),
     2177      862 => array('Revision' => 867, 'Function' => 'UpdateTo867'),
    21642178    ));
    21652179  }
  • trunk/Application/Version.php

    r866 r867  
    11<?php
    22
    3 $Revision = 866; // Subversion revision
    4 $DatabaseRevision = 862; // SQL structure revision
    5 $ReleaseTime = strtotime('2019-12-23');
     3$Revision = 867; // Subversion revision
     4$DatabaseRevision = 867; // SQL structure revision
     5$ReleaseTime = strtotime('2020-01-13');
  • trunk/Modules/Network/Network.php

    r865 r867  
    132132    $this->System->ModuleManager->Modules['Notify']->RegisterCheck('NetworkPort',
    133133      array($this, 'PortCheck'));
    134 
    135134
    136135    $this->System->RegisterPage('network', 'PageNetwork');
     
    816815    $OnlineText = array('<span style="color:red;">Nedostupný</span>', '<span style="color:green;">Dostupný</span>');
    817816    $Output = '';
    818     $Condition = 'WHERE (`NetworkInterface`.`Online` = '.$OnlineNow.') AND (`NetworkInterface`.`OnlineNotify` = '.$OnlinePrevious.') '.
    819       'AND (`NetworkInterface`.`LastOnline` <= "'.TimeToMysqlDateTime($Time - $MinDuration).'")';
     817    $Condition = 'WHERE (`NetworkInterface`.`LastOnline` <= "'.TimeToMysqlDateTime($Time - $MinDuration).'")';
     818    if ($OnlineNow != null) $Condition .= ' AND (`NetworkInterface`.`Online` = '.$OnlineNow.')';
     819    if ($OnlinePrevious != null) $Condition .= ' AND (`NetworkInterface`.`OnlineNotify` = '.$OnlinePrevious.')';
    820820    $DbResult3 = $this->Database->query('SELECT CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) AS `Name`, '.
    821821      '`NetworkInterface`.`Online`, `NetworkInterface`.`LastOnline` FROM `NetworkInterface` '.
     
    845845    $this->Database->query('UPDATE `NetworkInterface` SET `OnlineNotify` = `Online` '.
    846846      $Condition);
    847     return $Output;
     847    return array('Report' => $Output, 'Count' => $DbResult3->num_rows);
    848848  }
    849849
    850850  function ReachabilityCheck()
    851851  {
    852     $Output = '';
    853     $Output = $this->OnlineList('Nově online', 1, 0, 0);
    854     $Output .= $this->OnlineList('Nově offline', 0, 1, $this->MinNotifyTime);
    855     if($Output != '') $Output .= $this->OnlineList('Stále offline', 0, 0, 0);
    856     return($Output);
     852    $NewOnline = $this->OnlineList('Nově online', 1, 0, 0);
     853    $Output = $NewOnline['Report'];
     854    $NewOffline = $this->OnlineList('Nově offline', 0, 1, $this->MinNotifyTime);
     855    $Output .= $NewOffline['Report'];
     856    if ($Output != '')
     857    {
     858      $StillOffline = $this->OnlineList('Stále offline', 0, 0, 0);
     859      $Output .= $StillOffline['Report'];
     860    }
     861    $Offline = $this->OnlineList('Offline', 0, null, 0);
     862    return(array('Report' => $Output, 'Count' => $Offline['Count'], 'ShortTitle' => 'Odezva'));
    857863  }
    858864
     
    862868    $OnlineText = array('<span style="color:red;">Nedostupný</span>', '<span style="color:green;">Dostupný</span>');
    863869    $Output = '';
    864     $Condition = 'WHERE (`NetworkPort`.`Online` = '.$OnlineNow.') AND (`NetworkPort`.`OnlineNotify` = '.$OnlinePrevious.') '.
    865       'AND (`NetworkPort`.`LastOnline` <= "'.TimeToMysqlDateTime($Time - $MinDuration).'")';
     870    $Condition = 'WHERE (`NetworkPort`.`LastOnline` <= "'.TimeToMysqlDateTime($Time - $MinDuration).'")';
     871    if ($OnlineNow != null) $Condition .= ' AND (`NetworkPort`.`Online` = '.$OnlineNow.')';
     872    if ($OnlinePrevious != null) $Condition .= ' AND (`NetworkPort`.`OnlineNotify` = '.$OnlinePrevious.')';
    866873    $DbResult3 = $this->Database->query('SELECT CONCAT(CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")), ":", `NetworkPort`.`Number`, "(", `NetworkPort`.`Name`, ")") AS `Name`, '.
    867874      '`NetworkPort`.`Online`, `NetworkPort`.`LastOnline` FROM `NetworkPort` '.
     
    871878      '(`NetworkInterface`.`LocalIP` != "") AND (`NetworkPort`.`Enabled` = 1)'.
    872879      'ORDER BY `Name` ASC');
    873     if($DbResult3->num_rows > 0)
     880    if ($DbResult3->num_rows > 0)
    874881    {
    875882      $Output .= $Title.'<br/>';
     
    892899    $this->Database->query('UPDATE `NetworkPort` SET `OnlineNotify` = `Online` '.
    893900      $Condition);
    894     return $Output;
     901    return array('Report' => $Output, 'Count' => $DbResult3->num_rows);
    895902  }
    896903
     
    898905  {
    899906    $Output = '';
    900     $Output = $this->PortCheckList('Nově online', 1, 0, 0);
    901     $Output .= $this->PortCheckList('Nově offline', 0, 1, $this->MinNotifyTime);
    902     if($Output != '') $Output .= $this->PortCheckList('Stále offline', 0, 0, 0);
    903     return($Output);
     907    $NewOnline = $this->PortCheckList('Nově online', 1, 0, 0);
     908    $Output .= $NewOnline['Report'];
     909    $NewOffline = $this->PortCheckList('Nově offline', 0, 1, $this->MinNotifyTime);
     910    $Output .= $NewOffline['Report'];
     911    if ($Output != '')
     912    {
     913      $StillOffline = $this->PortCheckList('Stále offline', 0, 0, 0);
     914      $Output .= $StillOffline['Report'];
     915    }
     916    $Offline = $this->PortCheckList('Offline', 0, null, 0);
     917    return(array('Report' => $Output, 'Count' => $Offline['Count'], 'ShortTitle' => 'Port'));
    904918  }
    905919}
  • trunk/Modules/Notify/Notify.php

    r830 r867  
    1515    $this->License = 'GNU/GPL';
    1616    $this->Description = 'Send notification messages to selected users';
    17     $this->Dependencies = array('User');
     17    $this->Dependencies = array('User', 'RSS');
    1818    $this->Checks = array();
    1919  }
     
    3939    ));
    4040    $this->System->RegisterCommandLine('notify', array($this, 'RunCheck'));
     41    $this->System->ModuleManager->Modules['RSS']->RegisterRSS(array('Title' => 'Notify log',
     42    'Channel' => 'notifylog', 'Callback' => array('ModuleNotify', 'ShowLogRSS'),
     43    'Permission' => array('Module' => 'Notify', 'Operation' => 'RSS')));
    4144  }
    4245
     
    5962    $Output = '';
    6063    $Content = '';
     64    $Title = '';
    6165
    6266    // Get output from checks
    6367    $DbResult2 = $this->Database->query('SELECT `Id`, `Name`, `SysName` FROM `NotifyCategory`');
    64     while($Category = $DbResult2->fetch_assoc())
     68    while ($Category = $DbResult2->fetch_assoc())
    6569    {
    66       if(array_key_exists($Category['SysName'], $this->Checks))
     70      if (array_key_exists($Category['SysName'], $this->Checks))
    6771      {
    68         $List = call_user_func($this->Checks[$Category['SysName']]['Callback']);
    69         if($List != '') {
     72        $Status = call_user_func($this->Checks[$Category['SysName']]['Callback']);
     73        if ($Status['Report'] != '')
     74        {
    7075          $Output .= 'Kategorie: '.$Category['Name'].":\n";
    7176          $Content .= 'Kategorie: '.$Category['Name']."<br>\n";
    72           $Content .= $List;
     77          $Content .= $Status['Report'];
    7378        }
     79        if (strlen($Title) > 0) $Title .= ', ';
     80        $Title .= $Status['ShortTitle'].':'.$Status['Count'];
    7481      }
    7582    }
     83
     84    $Time = time();
    7685
    7786    // Send content to users
     
    8190    while($User = $DbResult->fetch_assoc())
    8291    {
    83       $Time = time();
    8492      $Output .= 'User '.$User['Name'].'<br/>';
    8593
    8694      $this->Database->update('NotifyUser', '`Id`='.$User['Id'], array('LastTime' => TimeToMysqlDateTime($Time)));
    8795
    88       if(($User['Category'] == CONTACT_CATEGORY_EMAIL) and ($Content !='')) {
     96      if(($User['Category'] == CONTACT_CATEGORY_EMAIL) and ($Content != ''))
     97      {
    8998        $Mail = new Mail();
    9099        $Mail->Subject = 'Notification';
     
    102111
    103112      return($Output);
     113    }
     114
     115    if ($Content != '')
     116    {
     117      $this->Database->insert('NotifyLog', array(
     118        'Time' => TimeToMysqlDateTime($Time),
     119        'Title' => $Title,
     120        'Content' => $Content)
     121      );
    104122    }
    105123  }
     
    147165    $this->Database->query('DROP TABLE `NotifyCategory`');
    148166  }
     167
     168  function ShowLogRSS()
     169  {
     170    $this->ClearPage = true;
     171    $this->FormatHTML = false;
     172    Header('Content-Type: text/xml');
     173    $Count = 100;
     174
     175    $Output = '';
     176    $Items = array();
     177    $sql = 'SELECT Title,Content, UNIX_TIMESTAMP(`Time`) AS `Time` FROM `NotifyLog`'.
     178      ' ORDER BY `Time` DESC LIMIT '.$Count;
     179    $DbResult = $this->System->Database->query($sql);
     180    while($Line = $DbResult->fetch_assoc())
     181    {
     182      $Items[] = array
     183      (
     184        'Title' => $Line['Title'],
     185        'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/Notify.php'),
     186        'Description' => $Line['Content'],
     187        'Time' => $Line['Time'],
     188      );
     189    }
     190
     191    $RSS = new RSS();
     192    $RSS->Title = $this->System->Config['Web']['Title'].' - Záznamy upozornění';
     193    $RSS->Link = 'http://'.$this->System->Config['Web']['Host'].'/';
     194    $RSS->Description = 'Záznam upozornění '.$this->System->Config['Web']['Description'];
     195    $RSS->WebmasterEmail = $this->System->Config['Web']['AdminEmail'];
     196    $RSS->Items = $Items;
     197    return($RSS->Generate());
     198  }
    149199}
Note: See TracChangeset for help on using the changeset viewer.