OP5 Monitor ["OP5 Monitor"]
["Technical Reference"]

Configure list view columns

Overview

The following procedures explain how to change the columns displayed in all list views for a particular object type, such as hosts or services. If you want to create new list view definitions, see Manage list view filters.

For more information on how list views are used in OP5 Monitor, see List views in Introduction to monitoring hosts, services, and groups.

List view tables

The format of each list view type is defined in a specific table. For example, the table for host list views is called Hosts, so you specify changes to the host list views in that table.

For a complete reference of the columns available for each table, see List view filter column reference.

Add columns to list views

You specify which columns to display in list views in your OP5 Monitor account settings. For more information, see Customise list views in Customise your user interface.

By default, all the table definitions have default column settings, which sets them to display all non-custom columns. You can change the default settings to a comma-separated column list.

The format for adding new columns to tables is "<label>" = <data>, where:

  • <label> is the column name.
  • <data> is the source of data.

You can add the text above with or without spaces between the values and the equals sign.

For example, to add a host notes column, you add "Notes" = notes to the Table Hosts field in your account settings:

You can also add host notes to service list views by adding the object field variable host.notes to the Services table:

For more information about object field variables, see Object field variables.

Add clickable links to list view columns

You can create clickable links in list views by adding a column definition containing HTML code, for example, adding the text in Table Hosts creates a column called Asset ID in hosts list views, with a clickable link to an external inventory system:

"Asset ID" = "<a href=\"http://inventory.example.org/?asset=" + notes + "\">Asset " + notes + "</a>"

Add custom variables to column definitions

You can add a custom variable to a column in the format custom_variables.<VARIABLE_NAME>. For more information on custom variables and how to create them, see Create a new custom variable in Manage commands.

In list view syntax, custom variables are written without the underscore prefix. In the following example, custom variable _ASSETID is added to the HTML code example in the Add clickable links to list view columns procedure above:

"Asset ID" = "<a href=\"http://inventory.example.org/?asset=" + custom_variables.ASSETID + "\">Asset " + custom_variables.ASSETID + "</a>"

Remove columns from list views

You can remove a column from a list view by adding the column name with a minus sign before it, as in the following example:

Add column definitions using expressions

OP5 Monitor includes a language for creating column definitions as expressions. An expression can return a value of type string, number, Boolean, or list. Expressions can include any of the elements listed below.

Operators

Operator Example Description Order of priority
Equals a = b Compares the values, true if a equals b 1
Add a + b Computes the sum of a and b 2
Subtract a - b Computes the difference of a and b 2
Multiplication a * b Computes the product of a and b 3
Division a / b Divides b by a 3
Negation - a Changes a from positive to negative, for example 3 becomes -3 4
Parenthesis ( a ) Forces a to be evaluated first N/A

Object field variables

You can use variables to access field information about objects. Many of the variables return information about other objects, for example, the host name field is accessible to services by using the host.name variable.

You can construct column definitions using field variables, such as in the following services table example:

"Identifier" = host.name + ";" + description

For a complete reference of field variables you can use, see List view filter column reference.

Function calls

You can use function calls to manipulate and format data. The syntax is as follows:

functionname(arg, arg, arg, ...)

The functions available are listed in the table below.

Function Description
implode( separator, list ) Joins each element in the list to a string, with separator as the separator.
time( unixtimestamp ) Converts a Unix timestamp to a human readable time. Many columns return a timestamp, which needs to be processed with this function to be readable.
idx( id, val0, val1, val2, ... ) Returns the value of an argument, given the value of id. Useful for setting names for values such as states, for example idx( state, "Ok", "Warning", "Critical", "Unknown" )
urlencode( string ) Escapes a string to be used as an attribute in a URL. Useful when building links.
htmlescape( string ) Escapes a string to be visible on the page. Useful, for example, for plugin output to be visible without interfering with the rest of the custom column style.
link( relative_url, constant )

Builds a link to an internal OP5 Monitor page. relative_url is relative to http://monitor.example.org/monitor/index.php/.

For example: link( "extinfo/host?host=" + urlencode(host.name), "Host extinfo" )

nl2br( string ) Convert newlines to line breaks. This is useful for formatting long plugin outputs as a custom column. For example: nl2br( htmlescape( plugin_output + "\n" + long_plugin_output ) )

If statements

You can use if statements for conditional processing. The syntax is as follows:

if test-expression then expression-if-true else expression-if-false

For example:

if has_been_checked then "yes" else "no"

List comprehension

You can use list comprehension to apply an expression to each element of a list. The syntax is as follows:

[ for-every-element-expression for variable in list-expression ]

OP5 Monitor applies for-every-element-expression to each element in the list-expression list in turn, setting variable to the element value.

The following example creates a link to the extinfo for each of a host's services in the host table.

[ link( "/extinfo/details?host=" + urlencode(name) + "&service=" + urlencode(svc), htmlescape(svc) ) for svc in services ]

name comes from the host, which also includes the services field, and the svc variable value is set by the list comprehension in the first expression which generates the link.

You can apply filters in a list comprehension to limit the number of values returned, such as an if statement:

for-every-element-expression for variable in list-expression if filter-expression ]

You can rewrite the earlier statement with an if statement filter, to output only services named "PING", as follows:

[ link( "/extinfo/details?host=" + urlencode(name) + "&service=" + urlencode(svc), htmlescape(svc) ) for svc in services if svc = "PING" ]

List elements

You can access an indexed element of a list by adding [id] as an integer value. The first attribute of the statement needs to be a variable, not an expression. For example:

"First service" = services[0]

You can use this in combination with host field services_with_info and a list comprehension.

Custom column language reference

You can find a complete reference of the custom column language syntax on your OP5 Monitor server, by entering URL https://<op5_monitor_server>/monitor/modules/lsfilter/html/LSColumnsVisualization.html