You are here

class LagoonLogstashPusher in Lagoon Logs 7

Hierarchy

Expanded class hierarchy of LagoonLogstashPusher

File

lib/LagoonLogstashPusher.php, line 3

View source
class LagoonLogstashPusher {
  public static function pushUdp($host, $port, $payload) {
    $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    if (!$socket) {
      throw new Exception('Could not open UDP socket for logstash: ' . $host . ':' . $port);
    }
    try {
      $msg = json_encode($payload) . "\n";
      if (!@socket_sendto($socket, $msg, strlen($msg), $flags = 0, $host, $port)) {
        throw new Exception('Could not send message to Logstash server: ' . $host . ':' . $port);
      }
    } catch (Exception $ex) {

      //we'll rethrow this, but we need to run some cleanup
      throw $ex;
    } finally {
      socket_close($socket);
    }
  }

}

Members