/*
** SellaNMS
** $Id: syslog.h,v 1.4 2005/11/07 01:17:01 sella Exp $
** Copyright (c) 2001-2005 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

#ifndef __DGS_OUTPUT_SYSLOG_H
#define __DGS_OUTPUT_SYSLOG_H

#ifdef HAVE_CONFIG_H
	#include "config.h"
#endif

#include "defaults.h"
#include "common/util.h"
#include "policy_framework/policy_framework.h"
#include "storage/storage.h"
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>

#define OUTPUT_SYSLOG_INTERVAL_DEF		15		//15 sec
#define OUTPUT_SYSLOG_INTERVAL_MIN		1		//1 sec
#define OUTPUT_SYSLOG_INTERVAL_MAX		900	//15 min
#define OUTPUT_SYSLOG_INTERVAL_MLT		1000000
#define OUTPUT_SYSLOG_QUEUEDEPTH_DEF	250
#define OUTPUT_SYSLOG_QUEUEDEPTH_MIN	1
#define OUTPUT_SYSLOG_QUEUEDEPTH_MAX	2500

#define OUTPUT_SYSLOG_FACILITY_DEF LOG_USER
#define OUTPUT_SYSLOG_SEVERITY_DEF LOG_INFO

static const struct __facility_names {
	const char *name;
} facility_names[] = {
	{ "kern" },
	{ "user" },
	{ "mail" },
	{ "daemon" },
	{ "auth" },
	{ "syslog" },
	{ "lpr" },
	{ "news" },
	{ "uucp" },
	{ "cron" },
	{ "authpriv" },
	{ "ftp" },
	{ "reserved" },
	{ "reserved" },
	{ "reserved" },
	{ "reserved" },
	{ "local0" },
	{ "local1" },
	{ "local2" },
	{ "local3" },
	{ "local4" },
	{ "local5" },
	{ "local6" },
	{ "local7" },
	{ NULL }
};

static const struct __severity_names {
	const char *name;
} severity_names[] = {
	{ "emerg" },
	{ "alert" },
	{ "crit" },
	{ "err" },
	{ "warning" },
	{ "notice" },
	{ "info" },
	{ "debug" },
	{ NULL }
};

typedef struct output_t {
   unsigned long  id;
   string         timestamp;
   time_t         unix_timestamp;
   string         element;
   string         interface;
   string         ip;
   string         source;
   string         module;
   string         protocol;
   string         channel;
   string         status;
   string         brief;
   string         detail;
} _output_t;

class Syslog {
	public:
		Syslog();
		virtual ~Syslog();
		virtual RESULT execute();
		virtual RESULT readConfig();

	protected:
		virtual void printConfig();
		virtual RESULT policyInputNext(variable_binding_t &policy_input);
		virtual RESULT processPolicyOutput(variable_binding_t &policy_output);
		virtual RESULT readOutput(const string &module);
		virtual RESULT deleteOutput(slist<unsigned long> &output_ids);
		virtual int getFacility(string facility);
		virtual int getSeverity(string severity);

      PolicyFramework inputPolicy;
      PolicyFramework outputPolicy;

	private:
		Storage storage;
		slist<output_t> output;

		unsigned long interval;
		unsigned long queueDepth;
		int priority;
};

#endif

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim600: fdm=marker
** vim: noet ts=3 sw=3
*/
