File: 1.11.0a/server/extras/events/syslog.php (View as HTML)

  1: <?php // syslog.php version 0.01 17/08/2009
  2: /* -------------------------------------------------------------
  3: This file is part of FreeNATS
  4: 
  5: FreeNATS is (C) Copyright 2008-2009 PurplePixie Systems
  6: 
  7: FreeNATS is free software: you can redistribute it and/or modify
  8: it under the terms of the GNU General Public License as published by
  9: the Free Software Foundation, either version 3 of the License, or
 10: (at your option) any later version.
 11: 
 12: FreeNATS is distributed in the hope that it will be useful,
 13: but WITHOUT ANY WARRANTY; without even the implied warranty of
 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15: GNU General Public License for more details.
 16: 
 17: You should have received a copy of the GNU General Public License
 18: along with FreeNATS.  If not, see www.gnu.org/licenses
 19: 
 20: For more information see www.purplepixie.org/freenats
 21: -------------------------------------------------------------- */
 22: 
 23: /* Description:
 24: 
 25: This is a custom event handler for FreeNATS v1 and relies on the following
 26: event types: alert_action
 27: 
 28: It also relies on the following FreeNATS class methods:
 29: 	TFreeNATS::Event, AddEventHandler
 30: 
 31: USAGE INSTRUCTIONS:
 32: 
 33: Place into the server/base/site/events directory being sure to keep a .php
 34: extension on the end of the file. Enable the system variable site.include.events
 35: (set to 1) to enable inclusion.
 36: 
 37: Create an alert action of the type message queue and with the name "_syslog"
 38: (without the quotes).
 39: 
 40: Alerts to this alert action will be piped to syslog.
 41: 
 42: Please note this may well not work when using the "test action" option in
 43: the configuration dependent on your system security setup.
 44: 
 45: */
 46: 
 47: 
 48: 
 49: 
 50: global $NATS;
 51: if (isset($NATS))
 52: {
 53: 
 54: 
 55: function alert_action_syslog($data)
 56: {
 57: 	global $NATS;
 58: 	$NATS->Event("Syslog AA Called for ".$data['name'],10,"Syslog","Start");
 59: 	if ($data['name']!="_syslog") return false;
 60: 	$lvl=LOG_ERR;
 61: 	
 62: 	define_syslog_variables();
 63: 	openlog("FreeNATS", LOG_PID | LOG_PERROR, LOG_LOCAL0);
 64: 
 65: 	if (syslog($lvl,$data['data'])===false)
 66: 		$NATS->Event("Syslog Failed for ".$data['data'],2,"Syslog","Write");
 67: 	else
 68: 		$NATS->Event("Syslog Succeeded for ".$data['data'],10,"Syslog","Write");
 69: 	closelog();
 70: 	
 71: 	return true;
 72: }
 73: 
 74: $NATS->AddEventHandler("alert_action","alert_action_syslog");
 75: 
 76: 
 77: 
 78: 
 79: } // end of isset($NATS) block
 80: ?>