= $sla['sla_limit_high']) { $limit_msg = ', Timeout exceeded'; $sla_state['rtt_event'] = 'alert'; } elseif ($sla_state['rtt_value'] >= $sla['sla_limit_high_warn']) { $limit_msg = ', Threshold exceeded'; $sla_state['rtt_event'] = 'warning'; } } if ($sla_state['rtt_event'] === 'ok' && $rtt_loss_percent >= 50) { $limit_msg = ', Probes loss >= 50%'; $sla_state['rtt_event'] = 'warning'; // Set to warning, because alert only on full SLA down } } // Last change time if (empty($sla['rtt_last_change'])) { // If last change never set, use current time $sla['rtt_last_change'] = $sla_polled_time; } if (($sla['rtt_sense'] != $sla_state['rtt_sense']) || ($sla['rtt_event'] != $sla_state['rtt_event'])) { // SLA sense changed, log and set rtt_last_change $sla_state['rtt_last_change'] = $sla_polled_time; if ($sla['rtt_sense']) // Log only if old sense not empty { log_event('SLA changed: [#' . $index . ', ' . $sla['sla_tag'] . '] ' . $sla['rtt_event'] . ' -> ' . $sla_state['rtt_event'] . ' (value: ' . $sla_state['rtt_value'] . 'ms, event: ' . $sla_state['rtt_sense'] . $limit_msg . ')', $device, 'sla', $sla['sla_id'], 'warning'); } } else { // If sense not changed, leave old last_change $sla_state['rtt_last_change'] = $sla['rtt_last_change']; } // Compatibility with old code if (empty($sla['sla_graph'])) { if (str_contains($sla['rtt_type'], 'jitter')) { $sla['sla_graph'] = 'jitter'; } else { $sla['sla_graph'] = 'echo'; } } switch ($sla['sla_graph']) { case 'jitter': $rrd_filename = 'sla_jitter-' . $rrd_index . '.rrd'; $rrd_ds .= ' DS:rtt_minimum:GAUGE:600:0:300000 DS:rtt_maximum:GAUGE:600:0:300000 DS:rtt_success:GAUGE:600:0:300000 DS:rtt_loss:GAUGE:600:0:300000'; if (is_numeric($sla_state['rtt_success'])) { $rrd_value .= ':' . $sla_state['rtt_minimum'] . ':' . $sla_state['rtt_maximum'] . ':' . $sla_state['rtt_success'] . ':' . $sla_state['rtt_loss']; } else { $rrd_value .= ':U:U:U:U'; } //var_dump($rrd_ds); //$graphs['sla-'.$sla['rtt_type']] = TRUE; break; case 'echo': default: //$graphs['sla'] = TRUE; } // Update SQL State dbUpdate($sla_state, 'slas', '`sla_id` = ?', [$sla['sla_id']]); // Check alerts $metrics = []; $metrics['rtt_value'] = $sla_state['rtt_value']; $metrics['rtt_sense'] = $sla_state['rtt_sense']; $metrics['rtt_sense_uptime'] = $sla_polled_time - $sla_state['rtt_last_change']; $metrics['rtt_event'] = $sla_state['rtt_event']; $metrics['rtt_minimum'] = $sla_state['rtt_minimum']; $metrics['rtt_maximum'] = $sla_state['rtt_maximum']; $metrics['rtt_success'] = $sla_state['rtt_success']; $metrics['rtt_loss'] = $sla_state['rtt_loss']; $metrics['rtt_loss_percent'] = $rtt_loss_percent; check_entity('sla', $sla, $metrics); //echo("SLA " . $sla['sla_index'] . ": " . $sla['rtt_type'] . " " . $sla['sla_owner'] . " " . $sla['sla_tag']. "... "); //echo($sla_state['rtt_value'] . 'ms at ' . format_unixtime($sla_state['rtt_unixtime']) . ', Sense code - "' . $sla_state['rtt_sense'] . '"'); $table_row = []; $table_row[] = "SLA " . $sla['sla_index']; $table_row[] = $sla['sla_mib']; $table_row[] = $sla['rtt_type']; $table_row[] = $sla['sla_owner']; $table_row[] = $sla['sla_tag']; $table_row[] = $sla_state['rtt_sense']; $table_row[] = $sla_state['rtt_value'] . 'ms'; $table_rows[] = $table_row; unset($table_row); } else { echo('NaN'); $rrd_value = 'U'; } rrdtool_create($device, $rrd_filename, $rrd_ds); rrdtool_update($device, $rrd_filename, 'N:' . $rrd_value); unset($rrd_ds, $rrd_value, $rrd_filename); } } echo(PHP_EOL); $headers = ['%WLabel%n', '%WMIB%n', '%WType%n', '%WOwner%n', '%WTag%n', '%WSense%n', '%WResponse%n']; print_cli_table($table_rows, $headers); if ($sla_db_count != $sla_snmp_count && !empty($sla_db)) { // Force rediscover slas print_debug("SLA total count for this device changed (DB: $sla_db_count, SNMP: $sla_snmp_count), force rediscover SLAs."); force_discovery($device, 'sla'); } // EOF