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 exit(integer) | Terminates the application.
23 ## <a id="object-accessor-functions"></a> Object Accessor Functions
25 These functions can be used to retrieve a reference to another object by name.
27 ### <a id="objref-get_check_command"></a> get_check_command
31 function get_check_command(name);
33 Returns the CheckCommand object with the specified name, or `null` if no such CheckCommand object exists.
35 ### <a id="objref-get_event_command"></a> get_event_command
39 function get_event_command(name);
41 Returns the EventCommand object with the specified name, or `null` if no such EventCommand object exists.
43 ### <a id="objref-get_notification_command"></a> get_notification_command
47 function get_notification_command(name);
49 Returns the NotificationCommand object with the specified name, or `null` if no such NotificationCommand object exists.
51 ### <a id="objref-get_host"></a> get_host
55 function get_notification_command(name);
57 Returns the Host object with the specified name, or `null` if no such Host object exists.
60 ### <a id="objref-get_service"></a> get_service
64 function get_service(host_name, service_name);
66 Returns the Service object with the specified name, or `null` if no such Service object exists.
69 ### <a id="objref-get_user"></a> get_user
73 function get_user(name);
75 Returns the User object with the specified name, or `null` if no such User object exists.
77 ### <a id="objref-get_host_group"></a> get_host_group
81 function get_host_group(name);
83 Returns the HostGroup object with the specified name, or `null` if no such HostGroup object exists.
86 ### <a id="objref-get_service_group"></a> get_service_group
90 function get_service_group(name);
92 Returns the ServiceGroup object with the specified name, or `null` if no such ServiceGroup object exists.
94 ### <a id="objref-get_user_group"></a> get_user_group
98 function get_user_group(name);
100 Returns the UserGroup object with the specified name, or `null` if no such UserGroup object exists.
103 ### <a id="objref-get_time_period"></a> get_time_period
107 function get_time_period(name);
109 Returns the TimePeriod object with the specified name, or `null` if no such TimePeriod object exists.
112 ### <a id="objref-get_object"></a> get_object
116 function get_object(type, name);
118 Returns the object with the specified type and name, or `null` if no such object exists. `type` must refer
122 ### <a id="objref-get_objects"></a> get_objects
126 function get_objects(type);
128 Returns an array of objects whose type matches the specified type. `type` must refer
132 ## <a id="math-object"></a> Math object
134 The global `Math` object can be used to access a number of mathematical constants
137 ### <a id="math-e"></a> Math.E
141 ### <a id="math-ln2"></a> Math.LN2
143 Natural logarithm of 2.
145 ### <a id="math-ln10"></a> Math.LN10
147 Natural logarithm of 10.
149 ### <a id="math-log2e"></a> Math.LOG2E
151 Base 2 logarithm of E.
153 ### <a id="math-pi"></a> Math.PI
155 The mathematical constant Pi.
157 ### <a id="math-sqrt1_2"></a> Math.SQRT1_2
161 ### <a id="math-sqrt2"></a> Math.SQRT2
165 ### <a id="math-abs"></a> Math.abs
171 Returns the absolute value of `x`.
173 ### <a id="math-acos"></a> Math.acos
179 Returns the arccosine of `x`.
181 ### <a id="math-asin"></a> Math.asin
187 Returns the arcsine of `x`.
189 ### <a id="math-atan"></a> Math.atan
195 Returns the arctangent of `x`.
197 ### <a id="math-atan2"></a> Math.atan2
201 function atan2(y, x);
203 Returns the arctangent of the quotient of `y` and `x`.
205 ### <a id="math-ceil"></a> Math.ceil
211 Returns the smallest integer value not less than `x`.
213 ### <a id="math-cos"></a> Math.cos
219 Returns the cosine of `x`.
221 ### <a id="math-exp"></a> Math.exp
227 Returns E raised to the `x`th power.
229 ### <a id="math-floor"></a> Math.floor
235 Returns the largest integer value not greater than `x`.
237 ### <a id="math-isinf"></a> Math.isinf
243 Returns whether `x` is infinite.
245 ### <a id="math-isnan"></a> Math.isnan
251 Returns whether `x` is NaN (not-a-number).
253 ### <a id="math-log"></a> Math.log
259 Returns the natural logarithm of `x`.
261 ### <a id="math-max"></a> Math.max
267 Returns the largest argument. A variable number of arguments can be specified.
268 If no arguments are given -Infinity is returned.
270 ### <a id="math-min"></a> Math.min
276 Returns the smallest argument. A variable number of arguments can be specified.
277 If no arguments are given +Infinity is returned.
279 ### <a id="math-pow"></a> Math.pow
285 Returns `x` raised to the `y`th power.
287 ### <a id="math-random"></a> Math.random
293 Returns a pseudo-random number between 0 and 1.
295 ### <a id="math-round"></a> Math.round
301 Returns `x` rounded to the nearest integer value.
303 ### <a id="math-sign"></a> Math.sign
309 Returns -1 if `x` is negative, 1 if `x` is positive
312 ### <a id="math-sin"></a> Math.sin
318 Returns the sine of `x`.
320 ### <a id="math-sqrt"></a> Math.sqrt
326 Returns the square root of `x`.
328 ### <a id="math-tan"></a> Math.tan
334 Returns the tangent of `x`.
336 ## <a id="json-object"></a> Json object
338 The global `Json` object can be used to encode and decode JSON.
340 ### <a id="json-encode"></a> Json.encode
346 Encodes an arbitrary value into JSON.
348 ### <a id="json-decode"></a> Json.decode
354 Decodes a JSON string.
356 ## <a id="number-type"></a> Number type
358 ### <a id="number-to_string"></a> Number#to_string
362 function to_string();
364 The `to_string` method returns a string representation of the number.
369 example.to_string() /* Returns "7" */
371 ## <a id="boolean-type"></a> Boolean type
373 ### <a id="boolean-to_string"></a> Boolean#to_string
377 function to_string();
379 The `to_string` method returns a string representation of the boolean value.
384 example.to_string() /* Returns "true" */
386 ## <a id="string-type"></a> String type
388 ### <a id="string-find"></a> String#find
392 function find(str, start);
394 Returns the zero-based index at which the string `str` was found in the string. If the string
395 was not found -1 is returned. `start` specifies the zero-based index at which `find` should
396 start looking for the string (defaults to 0 when not specified).
400 "Hello World".find("World") /* Returns 6 */
402 ### <a id="string-len"></a> String#len
408 Returns the length of the string in bytes. Note that depending on the encoding type of the string
409 this is not necessarily the number of characters.
413 "Hello World".len() /* Returns 11 */
415 ### <a id="string-lower"></a> String#lower
421 Returns a copy of the string with all of its characters converted to lower-case.
425 "Hello World".lower() /* Returns "hello world" */
427 ### <a id="string-upper"></a> String#upper
433 Returns a copy of the string with all of its characters converted to upper-case.
437 "Hello World".upper() /* Returns "HELLO WORLD" */
439 ### <a id="string-replace"></a> String#replace
443 function replace(search, replacement);
445 Returns a copy of the string with all occurences of the string specified in `search` replaced
446 with the string specified in `replacement`.
448 ### <a id="string-split"></a> String#split
452 function split(delimiters);
454 Splits a string into individual parts and returns them as an array. The `delimiters` argument
455 specifies the characters which should be used as delimiters between parts.
459 "x-7,y".split("-,") /* Returns [ "x", "7", "y" ] */
461 ### <a id="string-substr"></a> String#substr
465 function substr(start, len);
467 Returns a part of a string. The `start` argument specifies the zero-based index at which the part begins.
468 The optional `len` argument specifies the length of the part ("until the end of the string" if omitted).
472 "Hello World".substr(6) /* Returns "World" */
474 ### <a id="string-to_string"></a> String#to_string
478 function to_string();
480 Returns a copy of the string.
482 ## <a id="array-type"></a> Array type
484 ### <a id="array-add"></a> Array#add
490 Adds a new value after the last element in the array.
492 ### <a id="array-clear"></a> Array#clear
498 Removes all elements from the array.
500 ### <a id="array-clone"></a> Array#clone
504 Returns a copy of the array. Note that for elements which are reference values (e.g. objects such
505 as arrays and dictionaries) only the references are copied.
507 ### <a id="array-contains"></a> Array#contains
511 function contains(value);
513 Returns true if the array contains the specified value, false otherwise.
515 ### <a id="array-len"></a> Array#len
521 Returns the number of elements contained in the array.
523 ### <a id="array-remove"></a> Array#remove
527 function remove(index);
529 Removes the element at the specified zero-based index.
531 ### <a id="array-set"></a> Array#set
535 function set(index, value);
537 Sets the element at the zero-based index to the specified value. The `index` must refer to an element
538 which already exists in the array.
540 ### <a id="array-sort"></a> Array#sort
544 function sort(less_cmp);
546 Returns a copy of the array where all items are sorted. The items are
547 compared using the `<` (less-than) operator. A custom comparator function
548 can be specified with the `less_cmp` argument.
550 ### <a id="array-join"></a> Array#join
554 function join(separator);
556 Joins all elements of the array using the specified separator.
558 ## <a id="dictionary-type"></a> Dictionary type
560 ### <a id="dictionary-clone"></a> Dictionary#clone
566 Returns a copy of the dictionary. Note that for elements which are reference values (e.g. objects such
567 as arrays and dictionaries) only the references are copied.
569 ### <a id="dictionary-contains"></a> Dictionary#contains
573 function contains(key);
575 Returns true if a dictionary item with the specified `key` exists, false otherwise.
577 ### <a id="dictionary-len"></a> Dictionary#len
583 Returns the number of items contained in the dictionary.
585 ### <a id="dictionary-remove"></a> Dictionary#remove
589 function remove(key);
591 Removes the item with the specified `key`. Trying to remove an item which does not exist
594 ### <a id="dictionary-set"></a> Dictionary#set
598 function set(key, value);
600 Creates or updates an item with the specified `key` and `value`.
602 ## <a id="scriptfunction-type"></a> Function type
604 ### <a id="scriptfunction-call"></a> Function#call
608 function call(thisArg, ...);
610 Invokes the function using an alternative `this` scope. The `thisArg` argument specifies the `this`
611 scope for the function. All other arguments are passed directly to the function.
615 function set_x(val) {
621 set_x.call(dict, 7) /* Invokes set_x using `dict` as `this` */
623 ### <a id="scriptfunction-callv"></a> Function#callv
627 function callv(thisArg, args);
629 Invokes the function using an alternative `this` scope. The `thisArg` argument specifies the `this`
630 scope for the function. The items in the `args` array are passed to the function as individual arguments.
634 function set_x(val) {
642 set_x.callv(dict, args) /* Invokes set_x using `dict` as `this` */