Trappers and loggers

Sending collected events as SNMP traps

spy.snmpCollector(trapper, oid, spcode, bindings)

Parameter trapper must be a reference to trapper object obtained using snmp.trapper() function. Traps will have their enterprise-oid field set to oid and all variables will have their keys starting with oid. Traps will be of enterpriseSpecific (6) type and specific code will be set to spcode.

Using trappers with spy

spy.trapperCollector(trapper, logLevel, tagExpr, msgExpr, errExpr, errField)

This function creates collector that will send messages via trapper. Several trapper types are available:

  • file trappers - trappers that log messages to log file;
  • syslog trappers - trappers that send syslog messages;
  • zabbix trappers - trappers that send traps directly to zabbix;

Arguments:

  • trapper - configured and started trapper object;
  • logLevel - log level (ZorkaLogLevel constant);
  • tagExpr - log tag;
  • msgExpr - log message (if call succeeds);
  • errExpr - log message (if error occurs);
  • errField - spy record field that contains intercepted exception object;

Logging to zorka log

spy.zorkaLog(level, tag, msg)
spy.zorkaLog(level, tag, msg, err)
spy.zorkaLogCond(level, tag, msg, cond)
spy.zorkaLogCond(level, tag, msg, err, cond)

These functions can be used to put messages into agent log. This might be useful for debugging purposes. Log level is one of TRACE, DEBUG, INFO, WARN, ERROR or FATAL strings. The tag value will appear where class name normally appears. Message msg or error message err can contain substitution macros and use data from trace record or call context.

For conditional log functions zorkaLogCond field name has to be passed via cond parameter. If given field value is null or false, log message won’t be generated.

Syslog trapper

Syslog integration module offers a trapper that can be consumed by spy trapper plugins and a standalone function that can be used to send syslog messages directly from bean shell code.

syslog.trapper()

syslog.trapper(id)
syslog.trapper(id, syslogServer, defaultHost)

Returns syslog logger object (and creates it if object doesn’t exist). See logger objects methods to see what it can do. There are two variants of this method: first one only looks for already configured logger and returns null if it finds nothing. Second one creates logger if necessary. Logger object is registered at syslog lib as id, syslog server address is passed as host name or ip address (with optional port number in host:port notation).

syslog.log()

syslog.log(id, severity, facility, tag, message)

Logs message to a logger identified by id. Integer parameters severity and facility have to adhere to syslog standard conventions. Message is tagged using tag parameter (typically program name or component name) and log message is passed via content parameter.

Severity and facility codes are defined directly in spy lib. The following severity codes are available: S_EMERGENCY, S_ALERT, S_CRITICAL, S_ERROR, S_WARNING, S_NOTICE, S_INFO, S_DEBUG. The following facility codes are valid: F_LOCAL0, F_LOCAL1, F_LOCAL2, F_LOCAL3, F_LOCAL4, F_LOCAL5, F_LOCAL6, F_LOCAL7, F_KERNEL, F_USER, F_MAIL, F_SYSTEM, F_AUTH1, F_SYSLOG, F_PRINTER, F_NETWORK, F_UUCP, F_CLOCK1, F_AUTH2, F_FTPD, F_NTPD, F_AUDIT, F_ALERT, F_CLOCK2.

syslog.remove()

syslog.remove(id)

Stops and unregisters logger identified by id. Logger’s thread will be stopped and UDP socket will be closed. Note that references to this logger object may be still used somewhere. In such case JVM won’t release such object but all attempts to log using it will be ignored.

Zabbix trapper

zabbix.trapper()

zabbix.trapper(id)
zabbix.trapper(id, serverAddr, defaultHost)
zabbix.remove(id)

Returns (and eventually creates) zabbix trapper. Newly created trappers are registered in zabbix library and will be returned every time trapper() function with the same id will be called. Parameters:

  • id - arbitrary string identifying trapper; must be unique in zabbix library;

  • serverAddr - address of zabbix server (plus optional port number in addr:port form);

  • defaultHost - default host name - will be used as host name if no other has been passed;

Last function stops and unregisters trapper registered in zabbix library.