Rules File Lookup Table Operations

Lookup tables provide a way to add extra information in an event. A lookup table consists of a list of keys
and values. It is defined with the table function and accessed using the lookup function.
The lookup function evaluates the expression in the keys of the named table and returns the associated
value. If the key is not found, an empty string is returned. The lookup function has the following syntax:
lookup(expression,tablename)
You can create a lookup table directly in the rules file or in a separate file.

Defining Lookup Tables in the Rules File
You can create a lookup table directly in the rules file using the following format:
table tablename={{"key","value"},{"key","value"}...}

For example, to create a table that matches a node name to the department the node is in:
table dept={{"node1","Technical"},{"node2","Finance"}}
You can access this lookup table in the rules file as follows:
@ExtraChar=lookup(@Node,dept)
This example uses the @Node field as the key. If the value of the @Node field matches a key in the table,
@ExtraChar is set to the corresponding value.
A lookup table can also have multiple columns. For example:
table example_table = {{"key1", "value1", "value2", "value3"}, {"key2", "val1", "val2",
"val3"}}
You can obtain values from a multiple value lookup table as follows:
[@Summary, @AlertKey, $error_code] = lookup("key1", "example_table")

Defining Lookup Tables in a Separate File
Rather than including the lookup table directly in the rules file, you can create the table in a separate file. If
you are specifying a single value, the file must be in the format:
key[TAB]value
key[TAB]value
To create a table in which the node name is matched to the department the node is in, use the following
format:
node1[TAB]"Technical"
node2[TAB]"Finance"
Specify the path to the lookup table file as an absolute or relative path. Relative paths start from the current
rules file directory. You can use environment variables in the path. For example:
table dept="$OMNIHOME/probes/solaris2/Dept"
You can then use this lookup table in the rules file as follows:
@ExtraChar=lookup(@Node,dept)
For multiple values, the format is:
key1[TAB]value1[TAB]value2[TAB]value3
key2[TAB]val1[TAB]val2[TAB]val3
You can also control how the probe processes external lookup tables with the LookupTableMode
property, described in Probe Properties and Command Line Options on page 60. This property determines
how errors are handled when external lookup tables do not have the same number of values on each line.
Specifying Default Table Values
You can specify a default option to handle an event that does not match any of the key values in a table. The
default statement must follow the specific table definition.
The following is an example for a table in the rules file:
table example_table =
{{"key1", "value1", "value2", "value3"},
{"key2", "val1", "val2", "val3"}}
default = {"defval1", "defval2", "defval3"}
The following is an example for a table in a separate file:
table dept="$OMNIHOME/probes/solaris2/Dept"
default = {"defval1", "defval2", "defval3"}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13315261/viewspace-331010/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/13315261/viewspace-331010/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值