Commit version 24.12.13800
This commit is contained in:
@ -1,15 +1,17 @@
|
||||
<?php
|
||||
|
||||
if ($_SESSION['userlevel'] < '7') { print_warning("Insufficient Permissions"); exit(); }
|
||||
if ($_SESSION['userlevel'] < '7') {
|
||||
print_warning("Insufficient Permissions");
|
||||
exit();
|
||||
}
|
||||
|
||||
echo generate_box_open(array('title' => 'Alert Association Rule Migration', 'padding' => TRUE, 'header-border' => TRUE));
|
||||
echo generate_box_open(['title' => 'Alert Association Rule Migration', 'padding' => TRUE, 'header-border' => TRUE]);
|
||||
|
||||
$checkers = cache_alert_rules();
|
||||
$assocs = cache_alert_assoc();
|
||||
|
||||
foreach($assocs as $assoc)
|
||||
{
|
||||
$checkers[$assoc['alert_test_id']]['assocs'][] = $assoc;
|
||||
foreach ($assocs as $assoc) {
|
||||
$checkers[$assoc['alert_test_id']]['assocs'][] = $assoc;
|
||||
}
|
||||
|
||||
//echo '<h4>Alert Rules</h4>';
|
||||
@ -19,182 +21,171 @@ echo 'This page will assist you to migrate from legacy association format to the
|
||||
//print_vars($checkers);
|
||||
echo generate_box_close();
|
||||
|
||||
foreach($checkers as $alert)
|
||||
{
|
||||
foreach ($checkers as $alert) {
|
||||
|
||||
if($vars['migrate'] == $alert['alert_test_id'] || (!$alert['alert_assoc'] && $vars['migrate'] == 'all'))
|
||||
{
|
||||
if ($vars['migrate'] == $alert['alert_test_id'] || (!$alert['alert_assoc'] && $vars['migrate'] == 'all')) {
|
||||
|
||||
print_message("Migrating ".$alert['alert_name']);
|
||||
print_message("Migrating " . $alert['alert_name']);
|
||||
|
||||
$ruleset = migrate_assoc_rules($alert);
|
||||
$ruleset = migrate_assoc_rules($alert);
|
||||
|
||||
dbUpdate(array('alert_assoc' => json_encode($ruleset)), 'alert_tests', '`alert_test_id` = ?', array($alert['alert_test_id']));
|
||||
dbDelete('alert_assoc', '`alert_test_id` = ?', array($alert['alert_test_id']));
|
||||
$alert['alert_assoc'] = json_encode($ruleset);
|
||||
update_alert_table($alert, FALSE);
|
||||
dbUpdate(['alert_assoc' => json_encode($ruleset)], 'alert_tests', '`alert_test_id` = ?', [$alert['alert_test_id']]);
|
||||
dbDelete('alert_assoc', '`alert_test_id` = ?', [$alert['alert_test_id']]);
|
||||
$alert['alert_assoc'] = json_encode($ruleset);
|
||||
update_alert_table($alert, FALSE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$checkers = cache_alert_rules();
|
||||
$assocs = cache_alert_assoc();
|
||||
|
||||
foreach($assocs as $assoc)
|
||||
{
|
||||
$checkers[$assoc['alert_test_id']]['assocs'][] = $assoc;
|
||||
foreach ($assocs as $assoc) {
|
||||
$checkers[$assoc['alert_test_id']]['assocs'][] = $assoc;
|
||||
}
|
||||
|
||||
foreach($checkers as $alert)
|
||||
{
|
||||
foreach ($checkers as $alert) {
|
||||
|
||||
//if($alert['alert_test_id'] != 11) { continue; }
|
||||
//if($alert['alert_test_id'] != 11) { continue; }
|
||||
|
||||
echo generate_box_open(array('title' => $alert['alert_name'], 'padding' => TRUE, 'header-border' => TRUE));
|
||||
echo generate_box_open(['title' => $alert['alert_name'], 'padding' => TRUE, 'header-border' => TRUE]);
|
||||
|
||||
if(!$alert['alert_assoc']) {
|
||||
if (!$alert['alert_assoc']) {
|
||||
|
||||
$ruleset = migrate_assoc_rules($alert);
|
||||
$ruleset = migrate_assoc_rules($alert);
|
||||
|
||||
$query = parse_qb_ruleset($alert['entity_type'], $ruleset, TRUE);
|
||||
$query = parse_qb_ruleset($alert['entity_type'], $ruleset, TRUE);
|
||||
|
||||
$data = dbFetchRows($query);
|
||||
$error = dbError();
|
||||
$data = dbFetchRows($query);
|
||||
$error = dbError();
|
||||
|
||||
$field = $config['entities'][$alert['entity_type']]['table_fields']['id'];
|
||||
$field = $config['entities'][$alert['entity_type']]['table_fields']['id'];
|
||||
|
||||
$existing_entities = get_alert_entities($alert['alert_test_id']);
|
||||
$entities = array();
|
||||
$existing_entities = get_alert_entities($alert['alert_test_id']);
|
||||
$entities = [];
|
||||
|
||||
foreach($data as $datum)
|
||||
{
|
||||
$entities[$datum[$field]] = array('entity_id' => $datum[$field], 'device_id' => $datum['device_id']);
|
||||
}
|
||||
foreach ($data as $datum) {
|
||||
$entities[$datum[$field]] = ['entity_id' => $datum[$field], 'device_id' => $datum['device_id']];
|
||||
}
|
||||
|
||||
$legacy = get_alert_entities_from_assocs($alert);
|
||||
$legacy = get_alert_entities_from_assocs($alert);
|
||||
|
||||
//r($legacy);
|
||||
//r($entities);
|
||||
//r($existing_entities);
|
||||
//r($legacy);
|
||||
//r($entities);
|
||||
//r($existing_entities);
|
||||
|
||||
$add = array_diff_key($entities, $existing_entities);
|
||||
$remove = array_diff_key($existing_entities, $entities);
|
||||
$add = array_diff_key($entities, $existing_entities);
|
||||
$remove = array_diff_key($existing_entities, $entities);
|
||||
|
||||
//print_vars(array_diff_key($legacy, $entities));
|
||||
//echo count($add) .' to add, '.count($remove).' to remove. <br />';
|
||||
//print_vars(array_diff_key($legacy, $entities));
|
||||
//echo count($add) .' to add, '.count($remove).' to remove. <br />';
|
||||
|
||||
$changed = count($add) + count($remote);
|
||||
$changed = count($add) + count($remote);
|
||||
|
||||
$result = count($data);
|
||||
$existing = count(get_alert_entities($alert['alert_test_id']));
|
||||
$result = count($data);
|
||||
$existing = count(get_alert_entities($alert['alert_test_id']));
|
||||
|
||||
echo '<div class="row">';
|
||||
echo '<div class="col-md-6">';
|
||||
echo '<div class="box box-solid">';
|
||||
echo '<div class="row">';
|
||||
echo '<div class="col-md-6">';
|
||||
echo '<div class="box box-solid">';
|
||||
|
||||
if(is_array($alert['assocs']))
|
||||
{
|
||||
if (is_array($alert['assocs'])) {
|
||||
|
||||
echo '<h4>Original Association Rules</h4>';
|
||||
echo '<h4>Original Association Rules</h4>';
|
||||
|
||||
echo('<table class="table table-condensed-more table-striped" style="margin-bottom: 0px;">');
|
||||
echo('<table class="table table-condensed-more table-striped" style="margin-bottom: 0px;">');
|
||||
|
||||
// Loop the associations which link this alert to this device
|
||||
foreach ($alert['assocs'] as $assoc_id => $assoc)
|
||||
{
|
||||
// Loop the associations which link this alert to this device
|
||||
foreach ($alert['assocs'] as $assoc_id => $assoc) {
|
||||
|
||||
echo('<tr>');
|
||||
echo('<td style="width: 50%">');
|
||||
if (is_array($assoc['device_attribs'])) {
|
||||
$text_block = [];
|
||||
foreach ($assoc['device_attribs'] as $attribute) {
|
||||
$text_block[] = escape_html($attribute['attrib'] . ' ' . $attribute['condition'] . ' ' . $attribute['value']);
|
||||
}
|
||||
echo('<code>' . implode('<br />', $text_block) . '</code>');
|
||||
} else {
|
||||
echo '<code>*</code>';
|
||||
}
|
||||
|
||||
echo('</td>');
|
||||
|
||||
echo('<td>');
|
||||
if (is_array($assoc['entity_attribs'])) {
|
||||
$text_block = [];
|
||||
foreach ($assoc['entity_attribs'] as $attribute) {
|
||||
$text_block[] = escape_html($attribute['attrib'] . ' ' . $attribute['condition'] . ' ' . $attribute['value']);
|
||||
}
|
||||
echo('<code>' . implode('<br />', $text_block) . '</code>');
|
||||
} else {
|
||||
echo '<code>*</code>';
|
||||
}
|
||||
echo('</td>');
|
||||
|
||||
echo('</tr>');
|
||||
|
||||
echo('<tr>');
|
||||
echo('<td style="width: 50%">');
|
||||
if (is_array($assoc['device_attribs']))
|
||||
{
|
||||
$text_block = array();
|
||||
foreach ($assoc['device_attribs'] as $attribute)
|
||||
{
|
||||
$text_block[] = escape_html($attribute['attrib'].' '.$attribute['condition'].' '.$attribute['value']);
|
||||
}
|
||||
echo('<code>'.implode('<br />', $text_block).'</code>');
|
||||
} else {
|
||||
echo '<code>*</code>';
|
||||
}
|
||||
// End loop of associations
|
||||
echo '</table>';
|
||||
} else {
|
||||
|
||||
echo('</td>');
|
||||
print_message("No Legacy Associations!");
|
||||
|
||||
echo('<td>');
|
||||
if (is_array($assoc['entity_attribs']))
|
||||
{
|
||||
$text_block = array();
|
||||
foreach ($assoc['entity_attribs'] as $attribute)
|
||||
{
|
||||
$text_block[] = escape_html($attribute['attrib'].' '.$attribute['condition'].' '.$attribute['value']);
|
||||
}
|
||||
echo('<code>'.implode('<br />', $text_block).'</code>');
|
||||
} else {
|
||||
echo '<code>*</code>';
|
||||
}
|
||||
echo('</td>');
|
||||
}
|
||||
echo '</div></div>';
|
||||
|
||||
echo('</tr>');
|
||||
|
||||
}
|
||||
// End loop of associations
|
||||
echo '</table>';
|
||||
} else {
|
||||
|
||||
print_message("No Legacy Associations!");
|
||||
|
||||
}
|
||||
echo '</div></div>';
|
||||
|
||||
echo '<div class="col-md-6">
|
||||
echo '<div class="col-md-6">
|
||||
<div class="box box-solid">
|
||||
<h4>New Association Ruleset</h4>';
|
||||
echo render_qb_rules($alert['entity_type'], $ruleset);
|
||||
echo ' </div>
|
||||
echo render_qb_rules($alert['entity_type'], $ruleset);
|
||||
echo ' </div>
|
||||
</div>';
|
||||
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
$c_exist = count($existing_entities);
|
||||
$c_legacy = count($legacy);
|
||||
$c_new = count($entities);
|
||||
$c_exist = count($existing_entities);
|
||||
$c_legacy = count($legacy);
|
||||
$c_new = count($entities);
|
||||
|
||||
//echo '<table class="table table-bordered"><tr><th>Database</th><td>'.count($existing_entities).'</td><th>Legacy Rules</th><td>'.count($legacy).'</td><th>New Ruleset</th><td>'.count($entities).'</td></tr></table>';
|
||||
//echo '<table class="table table-bordered"><tr><th>Database</th><td>'.count($existing_entities).'</td><th>Legacy Rules</th><td>'.count($legacy).'</td><th>New Ruleset</th><td>'.count($entities).'</td></tr></table>';
|
||||
|
||||
if ($changed != 0) {
|
||||
if ($changed != 0) {
|
||||
|
||||
print_error("Migration results don't match for group ".$alert['alert_name'].". Please report this to the Observium developers. (<b>DB</b>: ". $c_exist ." | <b>Old</b>: ".$c_legacy." | <b>New</b>: ".$c_new.")");
|
||||
print_error("Migration results don't match for group " . $alert['alert_name'] . ". Please report this to the Observium developers. (<b>DB</b>: " . $c_exist . " | <b>Old</b>: " . $c_legacy . " | <b>New</b>: " . $c_new . ")");
|
||||
|
||||
echo '<pre>';
|
||||
//print_r($alert['assocs']);
|
||||
echo '</pre>';
|
||||
echo '<pre>' . safe_json_encode($ruleset, JSON_PRETTY_PRINT) . '</pre>';
|
||||
echo '<pre>';
|
||||
//print_r($alert['assocs']);
|
||||
echo '</pre>';
|
||||
echo '<pre>' . safe_json_encode($ruleset, JSON_PRETTY_PRINT) . '</pre>';
|
||||
|
||||
r($query);
|
||||
r($query);
|
||||
|
||||
//r($add);
|
||||
//r($remove);
|
||||
//r($add);
|
||||
//r($remove);
|
||||
|
||||
} else {
|
||||
print_message("Migration results match! (<b>DB</b>: ". $c_exist ." | <b>Old</b>: ".$c_legacy." | <b>New</b>: ".$c_new.")", 'success');
|
||||
} else {
|
||||
print_message("Migration results match! (<b>DB</b>: " . $c_exist . " | <b>Old</b>: " . $c_legacy . " | <b>New</b>: " . $c_new . ")", 'success');
|
||||
|
||||
echo '<a class="btn btn-primary" href="'.generate_url($vars, array('migrate' => $alert['alert_test_id'])).'">Migrate Alert</a>';
|
||||
echo '<a class="btn btn-primary" href="' . generate_url($vars, ['migrate' => $alert['alert_test_id']]) . '">Migrate Alert</a>';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//echo "results: " . $result . "<br />";
|
||||
//echo "existing:" . $existing . "<br />";
|
||||
//echo "error:" . $error;
|
||||
//echo "results: " . $result . "<br />";
|
||||
//echo "existing:" . $existing . "<br />";
|
||||
//echo "error:" . $error;
|
||||
|
||||
//echo "</span>";
|
||||
//echo "</span>";
|
||||
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
echo 'Alert '.$alert['alert_name']. ' already has new-style association rules <br />';
|
||||
echo 'Alert ' . $alert['alert_name'] . ' already has new-style association rules <br />';
|
||||
|
||||
}
|
||||
echo generate_box_close();
|
||||
}
|
||||
echo generate_box_close();
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
Reference in New Issue
Block a user