1 # <a id="library-reference"></a> Library Reference
3 ## <a id="global-functions"></a> Global functions
6 --------------------------------|-----------------------
7 regex(pattern, text) | Returns true if the regex pattern matches the text, false otherwise.
8 match(pattern, text) | Returns true if the wildcard pattern matches the text, false otherwise.
9 len(value) | Returns the length of the value, i.e. the number of elements for an array or dictionary, or the length of the string in bytes.
10 union(array, array, ...) | Returns an array containing all unique elements from the specified arrays.
11 intersection(array, array, ...) | Returns an array containing all unique elements which are common to all specified arrays.
12 keys(dict) | Returns an array containing the dictionary's keys.
13 string(value) | Converts the value to a string.
14 number(value) | Converts the value to a number.
15 bool(value) | Converts the value to a bool.
16 random() | Returns a random value between 0 and RAND_MAX (as defined in stdlib.h).
17 log(value) | Writes a message to the log. Non-string values are converted to a JSON string.
18 log(severity, facility, value) | Writes a message to the log. `severity` can be one of `LogDebug`, `LogNotice`, `LogInformation`, `LogWarning`, and `LogCritical`. Non-string values are converted to a JSON string.
19 typeof(value) | Returns the type object for a value.
20 get_time() | Returns the current UNIX timestamp.
21 parse_performance_data(pd) | Parses a performance data string and returns an array describing the values.
22 exit(integer) | Terminates the application.
24 ## <a id="object-accessor-functions"></a> Object Accessor Functions
26 These functions can be used to retrieve a reference to another object by name.
28 ### <a id="objref-get_check_command"></a> get_check_command
32 function get_check_command(name);
34 Returns the CheckCommand object with the specified name, or `null` if no such CheckCommand object exists.
36 ### <a id="objref-get_event_command"></a> get_event_command
40 function get_event_command(name);
42 Returns the EventCommand object with the specified name, or `null` if no such EventCommand object exists.
44 ### <a id="objref-get_notification_command"></a> get_notification_command
48 function get_notification_command(name);
50 Returns the NotificationCommand object with the specified name, or `null` if no such NotificationCommand object exists.
52 ### <a id="objref-get_host"></a> get_host
56 function get_notification_command(name);
58 Returns the Host object with the specified name, or `null` if no such Host object exists.
61 ### <a id="objref-get_service"></a> get_service
65 function get_service(host_name, service_name);
67 Returns the Service object with the specified name, or `null` if no such Service object exists.
70 ### <a id="objref-get_user"></a> get_user
74 function get_user(name);
76 Returns the User object with the specified name, or `null` if no such User object exists.
78 ### <a id="objref-get_host_group"></a> get_host_group
82 function get_host_group(name);
84 Returns the HostGroup object with the specified name, or `null` if no such HostGroup object exists.
87 ### <a id="objref-get_service_group"></a> get_service_group
91 function get_service_group(name);
93 Returns the ServiceGroup object with the specified name, or `null` if no such ServiceGroup object exists.
95 ### <a id="objref-get_user_group"></a> get_user_group
99 function get_user_group(name);
101 Returns the UserGroup object with the specified name, or `null` if no such UserGroup object exists.
104 ### <a id="objref-get_time_period"></a> get_time_period
108 function get_time_period(name);
110 Returns the TimePeriod object with the specified name, or `null` if no such TimePeriod object exists.
113 ### <a id="objref-get_object"></a> get_object
117 function get_object(type, name);
119 Returns the object with the specified type and name, or `null` if no such object exists. `type` must refer
123 ### <a id="objref-get_objects"></a> get_objects
127 function get_objects(type);
129 Returns an array of objects whose type matches the specified type. `type` must refer
133 ## <a id="math-object"></a> Math object
135 The global `Math` object can be used to access a number of mathematical constants
138 ### <a id="math-e"></a> Math.E
142 ### <a id="math-ln2"></a> Math.LN2
144 Natural logarithm of 2.
146 ### <a id="math-ln10"></a> Math.LN10
148 Natural logarithm of 10.
150 ### <a id="math-log2e"></a> Math.LOG2E
152 Base 2 logarithm of E.
154 ### <a id="math-pi"></a> Math.PI
156 The mathematical constant Pi.
158 ### <a id="math-sqrt1_2"></a> Math.SQRT1_2
162 ### <a id="math-sqrt2"></a> Math.SQRT2
166 ### <a id="math-abs"></a> Math.abs
172 Returns the absolute value of `x`.
174 ### <a id="math-acos"></a> Math.acos
180 Returns the arccosine of `x`.
182 ### <a id="math-asin"></a> Math.asin
188 Returns the arcsine of `x`.
190 ### <a id="math-atan"></a> Math.atan
196 Returns the arctangent of `x`.
198 ### <a id="math-atan2"></a> Math.atan2
202 function atan2(y, x);
204 Returns the arctangent of the quotient of `y` and `x`.
206 ### <a id="math-ceil"></a> Math.ceil
212 Returns the smallest integer value not less than `x`.
214 ### <a id="math-cos"></a> Math.cos
220 Returns the cosine of `x`.
222 ### <a id="math-exp"></a> Math.exp
228 Returns E raised to the `x`th power.
230 ### <a id="math-floor"></a> Math.floor
236 Returns the largest integer value not greater than `x`.
238 ### <a id="math-isinf"></a> Math.isinf
244 Returns whether `x` is infinite.
246 ### <a id="math-isnan"></a> Math.isnan
252 Returns whether `x` is NaN (not-a-number).
254 ### <a id="math-log"></a> Math.log
260 Returns the natural logarithm of `x`.
262 ### <a id="math-max"></a> Math.max
268 Returns the largest argument. A variable number of arguments can be specified.
269 If no arguments are given -Infinity is returned.
271 ### <a id="math-min"></a> Math.min
277 Returns the smallest argument. A variable number of arguments can be specified.
278 If no arguments are given +Infinity is returned.
280 ### <a id="math-pow"></a> Math.pow
286 Returns `x` raised to the `y`th power.
288 ### <a id="math-random"></a> Math.random
294 Returns a pseudo-random number between 0 and 1.
296 ### <a id="math-round"></a> Math.round
302 Returns `x` rounded to the nearest integer value.
304 ### <a id="math-sign"></a> Math.sign
310 Returns -1 if `x` is negative, 1 if `x` is positive
313 ### <a id="math-sin"></a> Math.sin
319 Returns the sine of `x`.
321 ### <a id="math-sqrt"></a> Math.sqrt
327 Returns the square root of `x`.
329 ### <a id="math-tan"></a> Math.tan
335 Returns the tangent of `x`.
337 ## <a id="json-object"></a> Json object
339 The global `Json` object can be used to encode and decode JSON.
341 ### <a id="json-encode"></a> Json.encode
347 Encodes an arbitrary value into JSON.
349 ### <a id="json-decode"></a> Json.decode
355 Decodes a JSON string.
357 ## <a id="number-type"></a> Number type
359 ### <a id="number-to_string"></a> Number#to_string
363 function to_string();
365 The `to_string` method returns a string representation of the number.
370 example.to_string() /* Returns "7" */
372 ## <a id="boolean-type"></a> Boolean type
374 ### <a id="boolean-to_string"></a> Boolean#to_string
378 function to_string();
380 The `to_string` method returns a string representation of the boolean value.
385 example.to_string() /* Returns "true" */
387 ## <a id="string-type"></a> String type
389 ### <a id="string-find"></a> String#find
393 function find(str, start);
395 Returns the zero-based index at which the string `str` was found in the string. If the string
396 was not found -1 is returned. `start` specifies the zero-based index at which `find` should
397 start looking for the string (defaults to 0 when not specified).
401 "Hello World".find("World") /* Returns 6 */
403 ### <a id="string-contains"></a> String#contains
407 function contains(str);
409 Returns `true` if the string `str` was found in the string. If the string
410 was not found `false` is returned. Use [find](20-library-reference.md#string-find)
411 for getting the index instead.
415 "Hello World".contains("World") /* Returns true */
417 ### <a id="string-len"></a> String#len
423 Returns the length of the string in bytes. Note that depending on the encoding type of the string
424 this is not necessarily the number of characters.
428 "Hello World".len() /* Returns 11 */
430 ### <a id="string-lower"></a> String#lower
436 Returns a copy of the string with all of its characters converted to lower-case.
440 "Hello World".lower() /* Returns "hello world" */
442 ### <a id="string-upper"></a> String#upper
448 Returns a copy of the string with all of its characters converted to upper-case.
452 "Hello World".upper() /* Returns "HELLO WORLD" */
454 ### <a id="string-replace"></a> String#replace
458 function replace(search, replacement);
460 Returns a copy of the string with all occurences of the string specified in `search` replaced
461 with the string specified in `replacement`.
463 ### <a id="string-split"></a> String#split
467 function split(delimiters);
469 Splits a string into individual parts and returns them as an array. The `delimiters` argument
470 specifies the characters which should be used as delimiters between parts.
474 "x-7,y".split("-,") /* Returns [ "x", "7", "y" ] */
476 ### <a id="string-substr"></a> String#substr
480 function substr(start, len);
482 Returns a part of a string. The `start` argument specifies the zero-based index at which the part begins.
483 The optional `len` argument specifies the length of the part ("until the end of the string" if omitted).
487 "Hello World".substr(6) /* Returns "World" */
489 ### <a id="string-to_string"></a> String#to_string
493 function to_string();
495 Returns a copy of the string.
497 ## <a id="array-type"></a> Array type
499 ### <a id="array-add"></a> Array#add
505 Adds a new value after the last element in the array.
507 ### <a id="array-clear"></a> Array#clear
513 Removes all elements from the array.
515 ### <a id="array-clone"></a> Array#clone
519 Returns a copy of the array. Note that for elements which are reference values (e.g. objects such
520 as arrays and dictionaries) only the references are copied.
522 ### <a id="array-contains"></a> Array#contains
526 function contains(value);
528 Returns true if the array contains the specified value, false otherwise.
530 ### <a id="array-len"></a> Array#len
536 Returns the number of elements contained in the array.
538 ### <a id="array-remove"></a> Array#remove
542 function remove(index);
544 Removes the element at the specified zero-based index.
546 ### <a id="array-set"></a> Array#set
550 function set(index, value);
552 Sets the element at the zero-based index to the specified value. The `index` must refer to an element
553 which already exists in the array.
555 ### <a id="array-sort"></a> Array#sort
559 function sort(less_cmp);
561 Returns a copy of the array where all items are sorted. The items are
562 compared using the `<` (less-than) operator. A custom comparator function
563 can be specified with the `less_cmp` argument.
565 ### <a id="array-join"></a> Array#join
569 function join(separator);
571 Joins all elements of the array using the specified separator.
573 ## <a id="dictionary-type"></a> Dictionary type
575 ### <a id="dictionary-clone"></a> Dictionary#clone
581 Returns a copy of the dictionary. Note that for elements which are reference values (e.g. objects such
582 as arrays and dictionaries) only the references are copied.
584 ### <a id="dictionary-contains"></a> Dictionary#contains
588 function contains(key);
590 Returns true if a dictionary item with the specified `key` exists, false otherwise.
592 ### <a id="dictionary-len"></a> Dictionary#len
598 Returns the number of items contained in the dictionary.
600 ### <a id="dictionary-remove"></a> Dictionary#remove
604 function remove(key);
606 Removes the item with the specified `key`. Trying to remove an item which does not exist
609 ### <a id="dictionary-set"></a> Dictionary#set
613 function set(key, value);
615 Creates or updates an item with the specified `key` and `value`.
617 ## <a id="scriptfunction-type"></a> Function type
619 ### <a id="scriptfunction-call"></a> Function#call
623 function call(thisArg, ...);
625 Invokes the function using an alternative `this` scope. The `thisArg` argument specifies the `this`
626 scope for the function. All other arguments are passed directly to the function.
630 function set_x(val) {
636 set_x.call(dict, 7) /* Invokes set_x using `dict` as `this` */
638 ### <a id="scriptfunction-callv"></a> Function#callv
642 function callv(thisArg, args);
644 Invokes the function using an alternative `this` scope. The `thisArg` argument specifies the `this`
645 scope for the function. The items in the `args` array are passed to the function as individual arguments.
649 function set_x(val) {
657 set_x.callv(dict, args) /* Invokes set_x using `dict` as `this` */