NAME

Thruk::Utils - Utilities Collection for Thruk

DESCRIPTION

Utilities Collection for Thruk

METHODS

parse_date

  my $timestamp = parse_date($c, $string)

Format: 2010-03-02 00:00:00 parse given date and return timestamp

format_date

  my $date_string = format_date($string, $format)

return date from timestamp in given format

format_number

  my $string = format_number($number)

return number with thousands seperator

format_cronentry

  my $cron_string = format_cronentry($cron_entry)

return cron entry as string

read_cgi_cfg

  read_cgi_cfg($c);

parse the cgi.cfg and put it into $c->config

is_valid_regular_expression

  my $result = is_valid_regular_expression($expression)

return true if this is a valid regular expression

calculate_overall_processinfo

  my $process_info = calculate_overall_processinfo($process_info)

computes a combined status for process infos

get_start_end_for_timeperiod

  my($start, $end) = get_start_end_for_timeperiod($c,
                                                  $timeperiod,
                                                  $smon,
                                                  $sday,
                                                  $syear,
                                                  $shour,
                                                  $smin,
                                                  $ssec,
                                                  $emon,
                                                  $eday,
                                                  $eyear,
                                                  $ehour,
                                                  $emin,
                                                  $esec,
                                                  $t1,
                                                  $t2);

returns a start and end timestamp for a report date definition

get_start_end_for_timeperiod_from_param

  my($start, $end) = get_start_end_for_timeperiod_from_param($c)

returns a start and end timestamp for a report date definition will use cgi params for input

get_dynamic_roles

  get_dynamic_roles($c, $user)

gets the authorized_for_read_only role and group based roles

set_dynamic_roles

  set_dynamic_roles($c)

sets the authorized_for_read_only role and group based roles

set_message

  set_message($c, $style, $text, [ $details ])

set a message in an cookie for later display

append_message

  append_message($text)

append text to current message

ssi_include

  ssi_include($c)

puts the ssi templates into the stash

read_ssi

  read_ssi($c, $page, $type)

finds all ssi files for a page of the specified type and returns the ssi content. Executable ssi files are executed and the output is appended to the ssi content. Otherwise the content of the ssi file is appende to the ssi content.

read_resource_file

  read_resource_file($file, [ $macros ], [$with_comments])

returns a hash with all USER1-32 macros. macros can be a predefined hash.

version_compare

  version_compare($version1, $version2)

compare too version strings and return 1 if v1 >= v2

combine_filter

  combine_filter($operator, $filter)

combine filter by operator

array2hash

  array2hash($data, [ $key, [ $key2 ]])

create a hash by key

set_paging_steps

  set_paging_steps($c, $data)

sets the pagins stepts, needs string like:

  *100, 500, 1000, all

get_custom_vars

  get_custom_vars($c, $obj, [$prefix], [$add_host])

return custom variables in a hash

set_custom_vars

  set_custom_vars($c)

set stash value for all allowed custom variables

check_custom_var_list

  check_custom_var_list($varname, $allowed)

returns true if custom variable name is in the list of allowed variable names

normal_mktime

  normal_mktime($year,$mon,$day,$hour,$min,$sec)

returns normalized timestamp for given date

get_user_data

  get_user_data($c)

returns user data

store_user_data

  store_user_data($c, $data)

store user data for section

get_global_user_data

  get_global_user_data($c)

returns global user data

store_global_user_data

  store_global_user_data($c, $data)

store global user data for section

array_uniq

  array_uniq($array)

return uniq elements of array

logs2xls

  logs2xls($c)

save excel file by background job

savexls

  savexls($c)

save excel file by background job

get_pnp_url

  get_pnp_url($c, $object)

return pnp url for object (host/service)

get_histou_url

  get_histou_url($c, $object)

return histou url for object (host/service)

get_graph_url

  get_graph_url($c, $object)

return graph url for object (host/service)

get_perf_image

  get_perf_image($c, $hst, $svc, $start, $end, $width, $height, $source, $resize_grafana_images, $format, $showtitle)

return raw pnp/grafana image if possible. An empty string will be returned if no graph can be exported.

get_fake_session

  get_fake_session($c)

create and return fake session id for current user

get_action_url

  get_action_url($c, $escape_fun, $remove_render, $action_url, $host, $svc)

return action_url modified for object (host/service) if we use graphite escape_fun is use to escape special char (html or quotes) remove_render remove /render in action url

list

  list($ref)

return list of ref unless it is already a list

translate_host_status

  translate_host_status($status)

return name for status

choose_mobile

  choose_mobile($c, $url)

let the user choose a mobile page or not

update_cron_file

  update_cron_file($c, $section, $entries)

write crontab section

get_cron_time_entry

  get_cron_time_entry($cronentry)

return time part of crontab entry

set_user

  set_user($c, $username)

set and authenticate a user

switch_realuser

  switch_realuser($uid, $groups)

switch real user and groups

check_pid_file

  check_pid_file($c)

check and write pid file if none exists

restart_later

  restart_later($c, $redirect_url)

restart fcgi process and redirects to given page

wait_after_reload

  wait_after_reload($c, [$backend], [$timestamp])

wait up to 60 seconds till the core responds

get_cron_entries_from_param

  get_cron_entries_from_param($cronentry)

return array of cron entries from param

read_data_file

  read_data_file($filename)

return data for datafile

write_data_file

  write_data_file($filename, $data, [$changed_only])

write data to datafile

backup_data_file

  backup_data_file($filename, $targetfile, $mode, $max_backups, [$save_interval], [$force])

write data to datafile

decode_any

read and decode string from either utf-8 or iso-8859-1

ensure_utf8

    ensure_utf8($str)

makes sure the given string is utf8

which

    which($prog)

returns path to program or undef

reduce_number

  reduce_number($number, $unit, [$divisor])

return reduced number, ex 1024B -> 1KB

get_template_variable

  get_template_variable($c, $template, $variable)

return variable defined from template

precompile_templates

  precompile_templates($c)

precompile and load templates into memory

find_files

  find_files($folder, $pattern)

return list of files for folder and pattern

beautify_diff

  beautify_diff($text)

make diff output beauty

check_memory_usage

  check_memory_usage($c)

check if memory limit is above the threshold

base_folder

    base_folder($c)

return base etc folder

is_post

    is_post($c)

make sure this is a post request

check_csrf

    check_csrf($c)

ensure valid cross site request forgery token

get_plugin_name

    get_plugin_name(__FILE__, __PACKAGE__)

returns the name of the plugin

backends_list_to_hash

    backends_list_to_hash($c, $list)

returns array of backend ids converted as list of hashes

backends_hash_to_list

    backends_hash_to_list($c, $hashlist)

returns array of backends (inverts backends_list_to_hash function)

convert_wildcards_to_regex

    convert_wildcards_to_regex($string)

returns regular expression with wildcards replaced

AUTHOR

Sven Nierlein, 2009-present, <sven@nierlein.org>

LICENSE

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.