diff options
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | configure.ac | 42 | ||||
-rw-r--r-- | obj.h | 2 | ||||
-rw-r--r-- | plugins/omsnmp/.cvsignore | 6 | ||||
-rw-r--r-- | plugins/omsnmp/Makefile.am | 6 | ||||
-rw-r--r-- | plugins/omsnmp/omsnmp.c | 176 | ||||
-rw-r--r-- | queue.c | 2 | ||||
-rw-r--r-- | rsyslog.conf | 34 |
8 files changed, 242 insertions, 30 deletions
diff --git a/Makefile.am b/Makefile.am index 094a39f1..f15fe567 100644 --- a/Makefile.am +++ b/Makefile.am @@ -99,3 +99,7 @@ endif if ENABLE_PGSQL SUBDIRS += plugins/ompgsql endif + +if ENABLE_SNMP +SUBDIRS += plugins/omsnmp +endif diff --git a/configure.ac b/configure.ac index 0cb3b86b..ff043c86 100644 --- a/configure.ac +++ b/configure.ac @@ -329,6 +329,7 @@ AM_CONDITIONAL(ENABLE_MYSQL, test x$enable_mysql = xyes) AC_SUBST(mysql_cflags) AC_SUBST(mysql_libs) + # PostgreSQL support AC_ARG_ENABLE(pgsql, [AS_HELP_STRING([--enable-pgsql],[Enable PostgreSQL database support @<:@default=no@:>@])], @@ -363,6 +364,43 @@ AC_SUBST(pgsql_cflags) AC_SUBST(pgsql_libs) +# SNMP support +AC_ARG_ENABLE(snmp, + [AS_HELP_STRING([--enable-snmp],[Enable SNMP support @<:@default=no@:>@])], + [case "${enableval}" in + yes) enable_snmp="yes" ;; + no) enable_snmp="no" ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-snmp) ;; + esac], + [enable_snmp=no] +) +#if test "x$enable_snmp" = "xyes"; then +# I think we can delete that part -- rgerhards, 2008-01-22 +# AC_CHECK_PROG( +# [HAVE_PGSQL_CONFIG], +# [pg_config], +# [yes],,, +# ) +# if test "x${HAVE_PGSQL_CONFIG}" != "xyes"; then +# AC_MSG_FAILURE([pg_config not found in PATH]) +# fi +# END to-be-deleted +# here must go the check for netsnmp +# AC_CHECK_LIB( +# [pq], +# [PQconnectdb], +# [snmp_cflags="" +# snmp_libs="" +# ], +# [AC_MSG_FAILURE([netsnmp library is missing])], +# [-L`pg_config --libdir`] +# ) +#fi +AM_CONDITIONAL(ENABLE_SNMP, test x$enable_snmp = xyes) +AC_SUBST(snmp_cflags) +AC_SUBST(snmp_libs) + + AC_CONFIG_FILES([Makefile \ doc/Makefile \ plugins/imudp/Makefile \ @@ -373,7 +411,8 @@ AC_CONFIG_FILES([Makefile \ plugins/omtesting/Makefile \ plugins/omgssapi/Makefile \ plugins/ommysql/Makefile \ - plugins/ompgsql/Makefile]) + plugins/ompgsql/Makefile \ + plugins/omsnmp/Makefile]) AC_OUTPUT echo "****************************************************" @@ -385,6 +424,7 @@ echo "Regular expressions support enabled: $enable_regexp" echo "Zlib compression support enabled: $enable_zlib" echo "MySql support enabled: $enable_mysql" echo "PostgreSQL support enabled: $enable_pgsql" +echo "SNMP support enabled: $enable_snmp" echo "Large file support enabled: $enable_largefile" echo "Networking support enabled: $enable_inet" echo "Enable GSSAPI Kerberos 5 support: $want_gssapi_krb5" @@ -86,7 +86,7 @@ CHKiRet(objInfoSetMethod(pObjInfoOBJ, methodID, (rsRetVal (*)(void*)) pHdlr)) /* debug aides */ -#if 1 +#if 0 #define d_pthread_mutex_lock(x) {dbgprintf("mutex %p lock %s, %s(), line %d\n", (void*)x, __FILE__, __func__, __LINE__); \ pthread_mutex_lock(x); \ if(1)dbgprintf("mutex %p lock aquired %s, %s(), line %d\n",(void*)x, __FILE__, __func__, __LINE__); \ diff --git a/plugins/omsnmp/.cvsignore b/plugins/omsnmp/.cvsignore new file mode 100644 index 00000000..9730646f --- /dev/null +++ b/plugins/omsnmp/.cvsignore @@ -0,0 +1,6 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo diff --git a/plugins/omsnmp/Makefile.am b/plugins/omsnmp/Makefile.am new file mode 100644 index 00000000..662d882c --- /dev/null +++ b/plugins/omsnmp/Makefile.am @@ -0,0 +1,6 @@ +pkglib_LTLIBRARIES = omsnmp.la + +omsnmp_la_SOURCES = omsnmp.c +omsnmp_la_CPPFLAGS = -I$(top_srcdir) $(pthreads_cflags) $(mudflap_cflags) +omsnmp_la_LDFLAGS = $(mudflap_libs) -module -avoid-version +omsnmp_la_LIBADD = diff --git a/plugins/omsnmp/omsnmp.c b/plugins/omsnmp/omsnmp.c new file mode 100644 index 00000000..58b89c6a --- /dev/null +++ b/plugins/omsnmp/omsnmp.c @@ -0,0 +1,176 @@ +/* omsnmp.c + * + * This module sends an snmp trap. More text will come here soon ^^ + * + * This module will become part of the CVS and the rsyslog project because I think + * it is a generally useful debugging, testing and development aid for everyone + * involved with rsyslog. + * + * CURRENT SUPPORTED COMMANDS: + * + * :omsnmp:sleep <seconds> <milliseconds> + * + * Must be specified exactly as above. Keep in mind milliseconds are a millionth + * of a second! + * + * NOTE: read comments in module-template.h to understand how this file + * works! + * + * Copyright 2007 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of rsyslog. + * + * Rsyslog is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Rsyslog is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + */ +#include "config.h" +#include "rsyslog.h" +#include <stdio.h> +#include <stdarg.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <assert.h> +#include "syslogd.h" +#include "syslogd-types.h" +#include "cfsysline.h" +#include "module-template.h" + +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> + +MODULE_TYPE_OUTPUT + +/* internal structures + */ +DEF_OMOD_STATIC_DATA + +static uchar* pszTarget = NULL; + +typedef struct _instanceData { + uchar szTarget[MAXHOSTNAMELEN+1]; /* IP or hostname of Snmp Target*/ + +} instanceData; + +BEGINcreateInstance +CODESTARTcreateInstance +// pData->szTarget +ENDcreateInstance + + +BEGINdbgPrintInstInfo +CODESTARTdbgPrintInstInfo + dbgprintf("%s", pData->szTarget); + /* do nothing */ +ENDdbgPrintInstInfo + + +BEGINisCompatibleWithFeature +CODESTARTisCompatibleWithFeature + /* we are not compatible with repeated msg reduction feature, so do not allow it */ +ENDisCompatibleWithFeature + + +BEGINtryResume +CODESTARTtryResume +ENDtryResume + +BEGINdoAction +CODESTARTdoAction + dbgprintf("Sending SNMP Trap to '%s'\n", pData->szTarget); +ENDdoAction + + +BEGINfreeInstance +CODESTARTfreeInstance + /* we do not have instance data, so we do not need to + * do anything here. -- rgerhards, 2007-07-25 + */ +ENDfreeInstance + + +BEGINparseSelectorAct +CODESTARTparseSelectorAct +CODE_STD_STRING_REQUESTparseSelectorAct(0) + + /* code here is quick and dirty - if you like, clean it up. But keep + * in mind it is just a testing aid ;) -- rgerhards, 2007-12-31 + */ + if(!strncmp((char*) p, ":omsnmp:", sizeof(":omsnmp:") - 1)) { + p += sizeof(":omsnmp:") - 1; /* eat indicator sequence (-1 because of '\0'!) */ + } else { + ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED); + } +dbgprintf("0\n"); + + /* ok, if we reach this point, we have something for us */ + if((iRet = createInstance(&pData)) != RS_RET_OK) + goto finalize_it; + +dbgprintf("1\n"); + + ABORT_FINALIZE( RS_RET_CONFLINE_UNPROCESSED );// RS_RET_PARAM_ERROR ); +dbgprintf("2\n"); + + /* Failsave */ + if (pszTarget == NULL) + ABORT_FINALIZE( RS_RET_CONFLINE_UNPROCESSED );// RS_RET_PARAM_ERROR ); + + /* Copy Target */ + strncpy( (char*) pData->szTarget, (char*) pszTarget, sizeof( pData->szTarget -1 ) ); + +CODE_STD_FINALIZERparseSelectorAct +ENDparseSelectorAct + + +BEGINneedUDPSocket +CODESTARTneedUDPSocket +ENDneedUDPSocket + +/* Reset config variables for this module to default values. + */ +static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal) +{ + if (pszTarget != NULL) + free(pszTarget); + pszTarget = NULL; + + return RS_RET_OK; +} + + +BEGINmodExit +CODESTARTmodExit +if (pszTarget != NULL) + free(pszTarget); +ENDmodExit + + +BEGINqueryEtryPt +CODESTARTqueryEtryPt +CODEqueryEtryPt_STD_OMOD_QUERIES +ENDqueryEtryPt + + +BEGINmodInit() +CODESTARTmodInit + *ipIFVersProvided = 1; /* so far, we only support the initial definition */ +CODEmodInit_QueryRegCFSLineHdlr + CHKiRet(omsdRegCFSLineHdlr((uchar *)"actionsnmptarget", 0, eCmdHdlrGetWord, NULL, &pszTarget, STD_LOADABLE_MODULE_ID)); + CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID)); +ENDmodInit +/* + * vi:set ai: + */ @@ -57,7 +57,7 @@ DEFobjStaticHelpers /* debug aides */ -#if 1 +#if 0 #define d_pthread_mutex_lock(x) {dbgprintf("mutex %p lock %s, %s(), line %d\n", x, __FILE__, __func__, __LINE__); \ pthread_mutex_lock(x); \ if(1)dbgprintf("mutex %p lock aquired %s, %s(), line %d\n", x, __FILE__, __func__, __LINE__); \ diff --git a/rsyslog.conf b/rsyslog.conf index 3e1270ef..71398148 100644 --- a/rsyslog.conf +++ b/rsyslog.conf @@ -2,35 +2,15 @@ # If you do not load inputs, nothing happens! # You may need to set the module load path if modules are not found. -$ModLoad immark.so # provides --MARK-- message capability -$ModLoad imud.so # provides UDP syslog reception -$ModLoad imtcp.so # provides TCP syslog reception and GSS-API (if compiled to support it) +#$ModLoad immark.so # provides --MARK-- message capability +#$ModLoad imud.so # provides UDP syslog reception +#$ModLoad imtcp.so # provides TCP syslog reception and GSS-API (if compiled to support it) $ModLoad imuxsock.so # provides support for local system logging (e.g. via logger command) -$ModLoad imklog.so # kernel logging (formerly provided by rklogd) +#$ModLoad imklog.so # kernel logging (formerly provided by rklogd) -# Log all kernel messages to the console. -# Logging much else clutters up the screen. -#kern.* /dev/console +$ModLoad /home/al/sources/rsyslog/plugins/omsnmp/.libs/omsnmp.so -# Log anything (except mail) of level info or higher. -# Don't log private authentication messages! -*.info;mail.none;authpriv.none;cron.none -/var/log/messages +# $actionsnmptarget localhost -# The authpriv file has restricted access. -authpriv.* /var/log/secure +*.* :omsnmp: -# Log all the mail messages in one place. -mail.* -/var/log/maillog - - -# Log cron stuff -cron.* -/var/log/cron - -# Everybody gets emergency messages -*.emerg * - -# Save news errors of level crit and higher in a special file. -uucp,news.crit -/var/log/spooler - -# Save boot messages also to boot.log -local7.* /var/log/boot.log |