Aleksandr Trofimov 6 месяцев назад
Родитель
Сommit
b65620c88a
2 измененных файлов с 65 добавлено и 0 удалено
  1. 48 0
      inc/classes/BxDolAlerts.php
  2. 17 0
      install/sql/system.sql

+ 48 - 0
inc/classes/BxDolAlerts.php

@@ -145,6 +145,9 @@ class BxDolAlerts extends BxDol
             }
         }
 
+        // log alert
+        $this->logAlert();
+
         // call agents
         $oAi = BxDolAI::getInstance();
         if($aAgents = $oAi->getAgentsByAlertUnitAndAction($this->sUnit, $this->sAction)) {
@@ -206,6 +209,51 @@ class BxDolAlerts extends BxDol
 
         return $aResult;
     }
+
+    public function logAlert()
+    {
+        $oDb = BxDolDb::getInstance();
+        $aExtraRefs = [];
+        foreach($this->aExtras as $sKey => $mixedValue) {
+            if (preg_match('/^(ref|override|return)_/', $sKey) || preg_match('/_(ref|override|return)$/', $sKey) || $sKey == 'result' || $sKey == 'return' || $sKey == 'ret') {
+                $aExtraRefs[] = $sKey;
+            }
+        }
+        $aBind = [
+            'unit' => $this->sUnit,
+            'action' => $this->sAction,
+            'object' => $this->iObject,
+            'sender' => $this->iSender,
+            'extra' => json_encode($this->aExtras),
+            'extra_refs' => json_encode($aExtraRefs)
+        ];
+        $oDb->query("
+            INSERT INTO sys_alerts_log
+            SET
+                unit  = :unit,
+                action = :action,
+                object = :object,
+                sender = :sender,
+                extra  = :extra,
+                extra_refs  = :extra_refs,
+                ts     = UNIX_TIMESTAMP(),
+                counter_total = 1,
+                counter_24h = 1
+            ON DUPLICATE KEY UPDATE
+                object = :object,
+                sender = :sender,
+                extra  = :extra,
+                ts     = UNIX_TIMESTAMP(),
+                counter_total = counter_total + 1,
+                counter_24h = counter_24h + 1
+        ", $aBind);
+    }
+
+    static public function resetAlertsCounter24h()
+    {
+        $oDb = BxDolDb::getInstance();
+        $oDb->query("UPDATE sys_alerts_log SET counter_24h = 0");
+    }
 }
 
 class BxDolAlertsResponse extends BxDol

+ 17 - 0
install/sql/system.sql

@@ -2304,6 +2304,23 @@ SET @iIdHandler = LAST_INSERT_ID();
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('bx_messenger', 'got_jot', @iIdHandler);
 
+
+CREATE TABLE `sys_alerts_log` (
+  `id` int(11) unsigned NOT NULL auto_increment,
+  `unit` varchar(128) NOT NULL DEFAULT '',
+  `action` varchar(32) NOT NULL DEFAULT 'none',
+  `object` varchar(128) NOT NULL,
+  `sender` int(10) UNSIGNED NOT NULL DEFAULT 0,
+  `extra` text NOT NULL,
+  `extra_refs` text NOT NULL,
+  `ts` int(10) UNSIGNED NOT NULL,
+  `counter_total` int(10) UNSIGNED NOT NULL,
+  `counter_24h` int(10) UNSIGNED NOT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `unit_action` (`unit`,`action`)
+);
+
+
 -- --------------------------------------------------------