Event Console Example

From FreeNATS Wiki
Jump to: navigation, search

Introduction

This is a very simple piece of code to act as an event handler within FreeNATS. It will echo the text from an alert action called console to the main system console.

Please note that for security reasons this won't ever work to test an action - only for actually detected alerts.

The Code

<?php

global $NATS; // need this as we're included from a function

// define a function to handle the event function alert_action_console($data) { if ($data['name']!="console") return false; // return false if not our event

$cmd="echo \"FreeNATS: ".$data['data']."\" > /dev/console"; @exec($cmd); // echo the text to the console

return true; // return true to clear the queue }

// Now just register the event with $NATS... $NATS->AddEventHandler("alert_action","alert_action_console");

?>