splunk-extplugin.h
This documentation does not apply to the most recent version of Splunk. Click here for the latest version.
splunk-extplugin.h
This is the header file for the external api library. It can be found in $SPLUNK_HOME/include.
/* Copyright (C) 2005-2007 Splunk Inc. All Rights Reserved. Version 2.2 */
#ifndef SPLUNK_EXTPLUGIN_H
#define SPLUNK_EXTPLUGIN_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stdarg.h>
#include <time.h>
enum SplunkLogLevel {
SPLUNKLOG_DEBUG,
SPLUNKLOG_INFO,
SPLUNKLOG_WARN,
SPLUNKLOG_ERROR,
SPLUNKLOG_FATAL,
};
extern void SplunkVLog(enum SplunkLogLevel level, const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 0)))
#endif /* __GNUC__ */
;
extern void SplunkLog(enum SplunkLogLevel level, const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
#endif /* __GNUC__ */
;
extern void SplunkVExit(int rval, const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 0)))
__attribute__ ((noreturn))
#endif /* __GNUC__ */
;
extern void SplunkExit(int rval, const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
__attribute__ ((noreturn))
#endif /* __GNUC__ */
;
/* Convinience functions so you don't have to specify log level */
extern void SplunkDebug(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif /* __GNUC__ */
;
extern void SplunkInfo(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif /* __GNUC__ */
;
extern void SplunkWarn(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif /* __GNUC__ */
;
extern void SplunkError(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif /* __GNUC__ */
;
extern void SplunkFatal(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif /* __GNUC__ */
;
struct SplunkTransaction; /* Opaque type */
extern const char *SplunkGetRaw(struct SplunkTransaction *trans);
extern void SplunkSetRaw(struct SplunkTransaction *trans, const char *nval);
extern const char *SplunkGetConf(struct SplunkTransaction *trans);
extern void SplunkSetConf(struct SplunkTransaction *trans, const char *nval);
extern const char *SplunkGetDone(struct SplunkTransaction *trans);
extern void SplunkSetDone(struct SplunkTransaction *trans, const char *nval);
extern const char *SplunkGetHost(struct SplunkTransaction *trans);
extern void SplunkSetHost(struct SplunkTransaction *trans, const char *nval);
extern const char *SplunkGetMeta(struct SplunkTransaction *trans);
extern void SplunkSetMeta(struct SplunkTransaction *trans, const char *nval);
extern const char *SplunkGetPath(struct SplunkTransaction *trans);
extern void SplunkSetPath(struct SplunkTransaction *trans, const char *nval);
extern time_t SplunkGetTime(struct SplunkTransaction *trans);
extern void SplunkSetTime(struct SplunkTransaction *trans, time_t nval);
extern const char *SplunkGetType(struct SplunkTransaction *trans);
extern void SplunkSetType(struct SplunkTransaction *trans, const char *nval);
extern const char *SplunkGetIndex(struct SplunkTransaction *trans);
extern void SplunkSetIndex(struct SplunkTransaction *trans, const char *nval);
extern const char *SplunkGetInput(struct SplunkTransaction *trans);
extern void SplunkSetInput(struct SplunkTransaction *trans, const char *nval);
extern const char *SplunkGetSource(struct SplunkTransaction *trans);
extern void SplunkSetSource(struct SplunkTransaction *trans, const char *nval);
extern const char *SplunkGetSourceType(struct SplunkTransaction *trans);
extern void SplunkSetSourceType(struct SplunkTransaction *trans,
const char *nval);
extern const char *SplunkGetIndexTerms(struct SplunkTransaction *trans);
extern void SplunkSetIndexTerms(struct SplunkTransaction *trans,
const char *nval);
extern const char *SplunkGetReportingHost(struct SplunkTransaction *trans);
extern void SplunkSetReportingHost(struct SplunkTransaction *trans,
const char *nval);
/* Asks splunkd for a setting from the property map */
extern const char *SplunkConfig(struct SplunkTransaction *trans,
const char *key);
/* And from the XML config: */
extern const char *SplunkInstanceConfig(const char *key);
extern void SplunkProcess_SingleThreaded(int (*f)(struct SplunkTransaction *))
#ifdef __GNUC__
__attribute__ ((noreturn))
#endif /* __GNUC__ */
;
extern void SplunkProcess_SetEofHandler(void (*handler)(void));
extern void SplunkProcess_SetOomHandler(void (*handler)(void));
#ifdef __cplusplus
extern int splunk_transaction_is_supposed_to_be_opaque;
} // extern "C"
#include <string>
// This is a little evil -- even though we're an opaque type we allow
// C++-style method accesses
struct SplunkTransaction {
SplunkTransaction()
{
// This just generates a link-time error
splunk_transaction_is_supposed_to_be_opaque++;
}
#define make_methods(cname) \
const char *get##cname(void) \
{ \
return SplunkGet##cname(this); \
} \
void set##cname(const char *nval) \
{ \
SplunkSet##cname(this, nval); \
} \
void set##cname(const std::string &nval) \
{ \
set##cname(nval.c_str()); \
}
make_methods(Raw)
make_methods(Conf);
make_methods(Done);
make_methods(Host);
make_methods(Meta);
make_methods(Path);
time_t getTime(void)
{
return SplunkGetTime(this);
}
void setTime(time_t nval)
{
SplunkSetTime(this, nval);
}
make_methods(Type);
make_methods(Index);
make_methods(Input);
make_methods(Source);
make_methods(SourceType);
make_methods(IndexTerms);
make_methods(ReportingHost);
#undef make_methods
const char *config(const char *key)
{
return SplunkConfig(this, key);
}
const char *config(const std::string &key)
{
return SplunkConfig(this, key.c_str());
}
};
// We also provide a "Splunk::" namespace which allows clients to be written
// with a completely C++ binding
namespace Splunk {
typedef struct SplunkTransaction Transaction;
class InstanceConfig_IMPL {
public:
InstanceConfig_IMPL()
{
}
const char *operator[] (const char *confval) const
{
return SplunkInstanceConfig(confval);
}
const char *operator[] (const std::string &confval) const
{
return SplunkInstanceConfig(confval.c_str());
}
};
extern const InstanceConfig_IMPL InstanceConfig;
typedef enum SplunkLogLevel LogLevel;
void VLog(LogLevel level, const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 0)))
#endif // __GNUC__
;
void Log(LogLevel level, const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
#endif // __GNUC__
;
inline void Log(LogLevel level, const std::string &str)
{
Log(level, "%s", str.c_str());
}
void VExit(int rval, const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 0)))
__attribute__ ((noreturn))
#endif // __GNUC__
;
void Exit(int rval, const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
__attribute__ ((noreturn))
#endif // __GNUC__
;
void Exit(int rval, const std::string &str)
#ifdef __GNUC__
__attribute__ ((noreturn))
#endif // __GNUC__
;
void Exit(int rval)
#ifdef __GNUC__
__attribute__ ((noreturn))
#endif // __GNUC__
;
void VDebug(const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 0)))
#endif // __GNUC__
;
void Debug(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif // __GNUC__
;
inline void Debug(const std::string &str)
{
Debug("%s", str.c_str());
}
void VInfo(const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 0)))
#endif // __GNUC__
;
void Info(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif // __GNUC__
;
inline void Info(const std::string &str)
{
Info("%s", str.c_str());
}
void VWarn(const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 0)))
#endif // __GNUC__
;
void Warn(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif // __GNUC__
;
inline void Warn(const std::string &str)
{
Warn("%s", str.c_str());
}
void VError(const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 0)))
#endif // __GNUC__
;
void Error(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif // __GNUC__
;
inline void Error(const std::string &str)
{
Error("%s", str.c_str());
}
void VFatal(const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 0)))
#endif // __GNUC__
;
void Fatal(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif // __GNUC__
;
inline void Fatal(const std::string &str)
{
Fatal("%s", str.c_str());
}
class SingleThreadedProcessor {
virtual bool handler(Transaction *trans) = 0;
static int _shim_handler(Transaction *trans);
virtual void eof(void);
static void _shim_eof_handler(void);
virtual void oom(void);
static void _shim_oom_handler(void);
// Allow logging functions to be called directly as methods
// inside of ->handler()
protected:
static void vlog(LogLevel level, const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 0)))
#endif // __GNUC__
;
static void log(LogLevel level, const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
#endif // __GNUC__
;
static inline void log(LogLevel level, const std::string &str)
{
log(level, "%s", str.c_str());
}
static void vexit(int rval, const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 0)))
__attribute__ ((noreturn))
#endif // __GNUC__
;
static void exit(int rval, const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
__attribute__ ((noreturn))
#endif // __GNUC__
;
static void exit(int rval, const std::string &str)
#ifdef __GNUC__
__attribute__ ((noreturn))
#endif // __GNUC__
;
static void exit(int rval)
#ifdef __GNUC__
__attribute__ ((noreturn))
#endif // __GNUC__
;
static void vdebug(const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 0)))
#endif // __GNUC__
;
static void debug(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif // __GNUC__
;
static inline void debug(const std::string &str)
{
debug("%s", str.c_str());
}
static void vinfo(const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 0)))
#endif // __GNUC__
;
static void info(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif // __GNUC__
;
static inline void info(const std::string &str)
{
info("%s", str.c_str());
}
static void vwarn(const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 0)))
#endif // __GNUC__
;
static void warn(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif // __GNUC__
;
static inline void warn(const std::string &str)
{
warn("%s", str.c_str());
}
static void verror(const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 0)))
#endif // __GNUC__
;
static void error(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif // __GNUC__
;
static inline void error(const std::string &str)
{
error("%s", str.c_str());
}
static void vfatal(const char *fmt, va_list va)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 0)))
#endif // __GNUC__
;
static void fatal(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif // __GNUC__
;
static inline void fatal(const std::string &str)
{
fatal("%s", str.c_str());
}
public:
SingleThreadedProcessor()
{
}
virtual ~SingleThreadedProcessor()
{
}
void run(void)
#ifdef __GNUC__
__attribute__ ((noreturn))
#endif // __GNUC__
;
};
};
#endif /* __cplusplus */
#endif /* !SPLUNK_EXTPLUGIN_H */
This documentation applies to the following versions of Splunk: 2.1 , 2.2 , 2.2.1 , 2.2.3 , 2.2.6 View the Article History for its revisions.