Example #1
0
function alerts_list()
{
    //Go through all the hosts and determine if any alerts should be created
    global $hosts;
    $h = new Host();
    $hosts = $h->find();
    $alerts = new Alert();
    foreach ($hosts as $host) {
        foreach ($host->ports() as $port) {
            $status = $host->get_port_status($port, true);
            if ($status == 0) {
                if ($alert = $alerts->find("WHERE host_id = " . $host->id . " AND port = " . $port)) {
                    //There is already an alert for this, go through each user and see what their preference for this port is
                    send_user_alerts($host->id, $port, $alert->id, 'all');
                } else {
                    $alert = new alert();
                    $alert->message = "HOST: " . $host->name . "PORT: " . $port . "";
                    $alert->user_id = 1;
                    $alert->host_id = $host->id;
                    $alert->port = $port;
                    $alert->sent_on = time();
                    $alert->save();
                    send_user_alerts($host->id, $port, $alert->id, 'single');
                    //Go through each user and determine what their preference for this port is.
                }
            } else {
                //The port is up, but we need to set up reports if there is an existing one!
                if ($alert = $alerts->find("WHERE host_id = " . $host->id . " AND port = " . $port)) {
                    //There is already an alert for this, go through each user and see what their preference for this port is
                    send_user_alerts($host->id, $port, $alert->id, 'single');
                }
            }
        }
    }
    render();
}
Example #2
0
 private static function __sendAlert($alertsId, $message)
 {
     $alert = Alert::find($alertsId);
     if (!is_null($alert)) {
         $alerts_to = $alert->users;
         foreach ($alerts_to as $current) {
             if ($current->pivot->to_facebook) {
                 static::__sendFacebook($current->facebook_id, $message);
             }
             if ($current->pivot->to_sms) {
                 static::__sendSms($current->mobile, $message);
             }
             if ($current->pivot->to_email) {
                 static::__sendEmail(array($current->email, $current->display_name), $message);
             }
         }
     }
 }