Skip to content

Commit

Permalink
Update to Observium CE 24.4
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleHuisman committed Apr 30, 2024
1 parent 096c8e6 commit 7e57dbc
Show file tree
Hide file tree
Showing 1,667 changed files with 1,885,456 additions and 508,198 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Observium CE 23.9
Observium CE 24.4
58 changes: 0 additions & 58 deletions check-errors.php

This file was deleted.

32 changes: 21 additions & 11 deletions config_to_json.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@
chdir(dirname($argv[0]));

// Get options before definitions!
$options = getopt("o:d");
$options = getopt("o:dt");
$cload_time = microtime(TRUE);

if (isset($options['o'])) {
// Skip load full definitions, while not required on initial config
define('OBS_DEFINITIONS_SKIP', TRUE);
}
require_once("includes/observium.inc.php");

if (is_cli()) {
if (isset($options['o'])) {
// get filtered options
get_config_json($options['o']);
//print_vars($options);
} else {
// All config options
get_config_json();
//print(safe_json_encode($config));
}
if (!is_cli()) {
return;
}

if (isset($options['t'])) {
print_cli(OBS_PROCESS_NAME . ' Load time: ' . elapsed_time($cload_time, 4) . PHP_EOL);
exit;
}

if (isset($options['o'])) {
// get filtered options
get_config_json($options['o']);
} else {
// All config options
get_config_json();
}

// EOF
58 changes: 28 additions & 30 deletions discovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2023 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2024 Observium Limited
*
*/

chdir(dirname($argv[0]));

// Get options before definitions!
$options = getopt("h:i:m:n:p:U:dquaMV");
$options = getopt("h:i:m:n:p:U:dfquaMV");

include("includes/observium.inc.php");
include("includes/discovery/functions.inc.php");
Expand Down Expand Up @@ -66,10 +66,22 @@
}

if (isset($options['u']) || isset($options['U']) ||
(isset($options['h']) && in_array($options['h'], ['all', 'odd', 'even', 'none']))) {
(isset($options['h']) && in_array($options['h'], [ 'all', 'odd', 'even', 'none' ]))) {
$options['u'] = TRUE;
if (isset($options['f'])) {
//$options['U'] = TRUE;
}

include($config['install_dir'] . '/includes/update/update.php');
if ($updating) {
// DB schema updated. force alert/groups update
$options['a'] = TRUE;
}

// check remote poller params
if (OBS_DISTRIBUTED) {
check_local_poller();
}
} elseif (!isset($options['q'])) {
// Warn about need DB schema update
$db_version = get_db_version();
Expand Down Expand Up @@ -154,12 +166,13 @@
-i Discovery instance.
-n Discovery number.
-q Quiet output.
-a Force update Groups/Alerts table
-a Update Groups/Alerts table
-u Upgrade DB schema
-M Show globally enabled/disabled modules and exit.
-V Show version and exit.
DEBUGGING OPTIONS:
-f Force requested option
-d Enable debugging output.
-dd More verbose debugging output.
-m Specify modules (separated by commas) to be run.
Expand All @@ -181,7 +194,7 @@
//run_action_queue('device_delete');

// Update alert and group tables
run_action_queue('tables_update');
run_action_queue('tables_update', $options);
} else {
$silent = isset($options['q']);
if (function_exists('update_group_tables')) {
Expand All @@ -197,7 +210,7 @@
}

// For not new devices discovery, skip down devices
if ($options['h'] !== 'new') {
if ($options['h'] !== 'new' && !isset($options['f'])) {
$where .= ' AND `status` = ?';
$params[] = 1;
}
Expand All @@ -223,9 +236,7 @@

print_cli_heading("%WFinished discovery run at " . date("Y-m-d H:i:s"), 0);

$end = utime();
$run = $end - $start;
$discovery_time = substr($run, 0, 5);
$discovery_time = elapsed_time($start, 4);

// Update Group/Alert tables
if (($discovered_devices && !isset($options['m'])) || isset($options['a'])) {
Expand All @@ -235,9 +246,10 @@
print_message("Update alert and group tables added to queue [$action_id].");
//log_event("Device with hostname '$hostname' added to queue [$action_id] for addition on remote Poller [{$vars['poller_id']}].", NULL, 'info', NULL, 7);
} else {
// Not exist in CE
if (function_exists('update_group_tables')) {
update_group_tables($silent);
} // Not exist in CE
}
if (function_exists('update_alert_tables')) {
update_alert_tables($silent);
}
Expand All @@ -250,22 +262,8 @@
$doing = $device['hostname'];

// This discovery passed from wrapper and with process id
if ($config['poller_id'] > 0 &&
$poller = dbFetchRow('SELECT * FROM `pollers` WHERE `poller_id` = ?', [$config['poller_id']])) {
print_debug_vars($poller, 1);
$host_id = get_local_id();
$update = [];
if ($poller['host_id'] != $host_id) {
$update['host_id'] = $host_id;
log_event("Poller " . $config['poller_id'] . " host ID changed: '" . $poller['host_id'] . "' -> '" . $host_id . "'");
}
if ($poller['host_uname'] != php_uname()) {
$update['host_uname'] = php_uname();
log_event("Poller " . $config['poller_id'] . " host uname changed: '" . $poller['host_uname'] . "' -> '" . $update['host_uname'] . "'");
}
if (count($update)) {
dbUpdate($update, 'pollers', '`poller_id` = ?', [$config['poller_id']]);
}
if (OBS_DISTRIBUTED && !$options['u']) {
check_local_poller();
}
}
} elseif (!isset($options['q']) && !$options['u']) {
Expand All @@ -278,8 +276,8 @@

// Clean stale observium processes
$process_sql = "SELECT * FROM `observium_processes` WHERE `poller_id` = ? AND `process_start` < ?";
foreach (dbFetchRows($process_sql, [$config['poller_id'], $config['time']['fourhour']]) as $process) {
// We found processes in DB, check if it exist on system
foreach (dbFetchRows($process_sql, [ $config['poller_id'], get_time('fourhour') ]) as $process) {
// We found processes in DB, check if it exists on a system
print_debug_vars($process);
$pid_info = get_pid_info($process['process_pid']);
if (is_array($pid_info) && str_contains($pid_info['COMMAND'], $process['process_name'])) {
Expand Down
9 changes: 5 additions & 4 deletions housekeeping.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage cli
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2023 Observium Limited
* @package observium
* @subpackage cli
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2024 Observium Limited
*
*/

Expand All @@ -28,7 +28,7 @@
}

// Prevent running housekeeping on remote pollers (not needed, won't work properly, potential data loss vector)
if ($config['poller_id'] !== 0) {
if (!isset($options['f']) && $config['poller_id'] !== 0) {
print_message("%yHousekeeping only needs to be run on the main node. Do not run housekeeping on partitioned pollers.%n\n", 'color');
exit;
}
Expand Down Expand Up @@ -113,6 +113,7 @@
-p Clean up deleted ports
-b Clean up stale database entries
-A <age> Specifies maximum age for all modules (overrides configuration)
-f Force run Housekeeping on Poller ID other than 0 (main)
DEBUGGING OPTIONS:
-T Testing, not do any actions, only show counts.
Expand Down
20 changes: 14 additions & 6 deletions html/ajax/actions/alert_check_add.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* This file is part of Observium.
*
* @package observium
* @subpackage ajax
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2023 Observium Limited
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2024 Observium Limited
*
*/

Expand All @@ -17,15 +17,15 @@
}

$ok = TRUE;
foreach (['entity_type', 'alert_name', 'alert_severity', 'alert_conditions'] as $var) {
if (!isset($vars[$var]) || strlen($vars[$var]) == '0') {
foreach ([ 'entity_type', 'alert_name', 'alert_severity', 'alert_conditions' ] as $var) {
if (safe_empty($vars[$var])) {
$ok = FALSE;
$failed[] = $var;
}
}

if ($ok) {
if (dbExist('alert_tests', '`entity_type` = ? AND `alert_name` = ?', [$vars['entity_type'], $vars['alert_name']])) {
if (dbExist('alert_tests', '`entity_type` = ? AND `alert_name` = ?', [ $vars['entity_type'], $vars['alert_name'] ])) {
print_json_status('failed', "Alert Checker '{$vars['alert_name']}' already exist.");
return;
}
Expand All @@ -34,8 +34,16 @@

$conditions = [];
foreach (explode("\n", trim($vars['alert_conditions'])) as $cond) {
if (preg_match(OBS_PATTERN_XSS, $cond)) {
print_json_status('failed', "Prevent XSS payload.");
return;
}
$condition = [];
[$condition['metric'], $condition['condition'], $condition['value']] = explode(" ", trim($cond), 3);
[ $condition['metric'], $condition['condition'], $condition['value'] ] = explode(" ", trim($cond), 3);
if (!is_alpha($condition['metric'])) {
print_json_status('failed', "Incorrect condition metric '" . escape_html($condition['metric']) . "'");
return;
}
$conditions[] = $condition;
}
$check_array['conditions'] = safe_json_encode($conditions);
Expand Down
37 changes: 37 additions & 0 deletions html/ajax/actions/alert_entry_ignore_until_ok.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

if ($_SESSION['userlevel'] >= 8) {

if (is_intnum($vars['value'])) {

$alert_entry = get_alert_entry_by_id($vars['value']);

if(!count($alert_entry)) {
print_json_status('failed', 'Alert entry not found. No update performed.');
die;
}

$update_array = [];
if ($alert_entry['ignore_until_ok'] != 1) {
$update_array['ignore_until_ok'] = '1';
}
if ($alert_entry['alert_status'] == 0) {
$update_array['alert_status'] = '3';
}

if (count($update_array)) {
//r($alert_entry);
dbUpdate($update_array, 'alert_table', 'alert_table_id = ?', [$alert_entry['alert_table_id']]);
$alert_device = device_by_id_cache($alert_entry['device_id']);
//print_message("Alert entry [{$vars['form_alert_table_id']}] for device '{$alert_device['hostname']}' suppressed.");
print_json_status('ok', 'alert '.$vars['form_alert_table_id'].' ignored until ok. status updated.', ['update_array' => $update_array]);
}

unset($update_array);

// FIXME - eventlog? audit log?
}

} else {
print_json_status('failed', 'Action not permitted. Not performed.');
}
Loading

0 comments on commit 7e57dbc

Please sign in to comment.