ℹ️ Your data is safe here... unless you make the SNIP gods angry. And let's just say they have a really bad sense of humor.

From Angel Fontenla Gago, 6 Years ago, written in PHP.
This paste is a reply to Untitled from librenms
- view diff
Embed
  1. <?php
  2. namespace LibreNMS\Alert;
  3.  
  4. class AlertUtil
  5. {
  6.     /**
  7.      *
  8.      * Get the rule_id for a specific alert
  9.      *
  10.      * @param $alert_id
  11.      * @return mixed|null
  12.      */
  13.     private static function getRuleId($alert_id)
  14.     {
  15.         $query = "SELECT `rule_id` FROM `alerts` WHERE `id`=?";
  16.         return dbFetchCell($query, [$alert_id]);
  17.     }
  18.  
  19.     /**
  20.      *
  21.      * Get the transport for a given alert_id
  22.      *
  23.      * @param $alert_id
  24.      * @return array
  25.      */
  26.     public static function getAlertTransports($alert_id)
  27.     {
  28.         $query = "SELECT b.transport_id, b.transport_type, b.transport_name FROM alert_transport_map AS a LEFT JOIN alert_transports AS b ON b.transport_id=a.transport_or_group_id WHERE a.target_type='single' AND a.rule_id=? UNION DISTINCT SELECT d.transport_id, d.transport_type, d.transport_name FROM alert_transport_map AS a LEFT JOIN alert_transport_groups AS b ON a.transport_or_group_id=b.transport_group_id LEFT JOIN transport_group_transport AS c ON b.transport_group_id=c.transport_group_id LEFT JOIN alert_transports AS d ON c.transport_id=d.transport_id WHERE a.target_type='group' AND a.rule_id=?";
  29.         $rule_id = self::getRuleId($alert_id);
  30.         return dbFetchRows($query, [$rule_id, $rule_id]);
  31.     }
  32.  
  33.     /**
  34.      *
  35.      * Returns the default transports
  36.      *
  37.      * @return array
  38.      */
  39.     public static function getDefaultAlertTransports()
  40.     {
  41.         $query = "SELECT transport_id, transport_type FROM alert_transports WHERE is_default=true";
  42.         return dbFetchRows($query);
  43.     }
  44. }
  45.  
captcha