diff --git a/create/src/schema.tmpl b/create/src/schema.tmpl index d8427b6a3a8..dcbed0c5edf 100644 --- a/create/src/schema.tmpl +++ b/create/src/schema.tmpl @@ -2000,6 +2000,7 @@ FIELD |effective_date |t_integer |'0' |NOT NULL |0 FIELD |timezone |t_varchar(50) |'UTC' |NOT NULL |ZBX_NODATA FIELD |status |t_integer |'1' |NOT NULL |0 FIELD |description |t_text |'' |NOT NULL |0 +FIELD |og_min_down_severity |t_integer |'0' |NOT NULL |0 UNIQUE |1 |name TABLE|sla_schedule|sla_scheduleid|ZBX_DATA diff --git a/ui/app/controllers/CControllerSlaCreate.php b/ui/app/controllers/CControllerSlaCreate.php index 42b58c46933..adc85c5d1ac 100644 --- a/ui/app/controllers/CControllerSlaCreate.php +++ b/ui/app/controllers/CControllerSlaCreate.php @@ -38,6 +38,7 @@ class CControllerSlaCreate extends CControllerSlaCreateUpdate { 'service_tags' => 'required|array', 'description' => 'required|string', 'status' => 'in '.ZBX_SLA_STATUS_ENABLED, + 'og_min_down_severity' => 'in '.implode(',', range(0, 5)), 'excluded_downtimes' => 'array' ]; @@ -94,7 +95,7 @@ class CControllerSlaCreate extends CControllerSlaCreateUpdate { 'excluded_downtimes' => [] ]; - $fields = ['name', 'slo', 'period', 'timezone', 'description', 'excluded_downtimes']; + $fields = ['name', 'slo', 'period', 'timezone', 'description', 'og_min_down_severity', 'excluded_downtimes']; $this->getInputs($sla, $fields); diff --git a/ui/app/controllers/CControllerSlaEdit.php b/ui/app/controllers/CControllerSlaEdit.php index 5b39ed5c049..5a4b1da28a0 100644 --- a/ui/app/controllers/CControllerSlaEdit.php +++ b/ui/app/controllers/CControllerSlaEdit.php @@ -55,7 +55,7 @@ class CControllerSlaEdit extends CController { if ($this->hasInput('slaid')) { $this->sla = API::Sla()->get([ - 'output' => ['slaid', 'name', 'period', 'slo', 'effective_date', 'timezone', 'status', 'description'], + 'output' => ['slaid', 'name', 'period', 'slo', 'effective_date', 'timezone', 'status', 'description', 'og_min_down_severity'], 'selectServiceTags' => ['tag', 'operator', 'value'], 'selectSchedule' => ['period_from', 'period_to'], 'selectExcludedDowntimes' => ['name', 'period_from', 'period_to'], @@ -112,6 +112,7 @@ class CControllerSlaEdit extends CController { 'service_tags' => $this->sla['service_tags'], 'description' => $this->sla['description'], 'status' => $this->sla['status'], + 'og_min_down_severity' => $this->sla['og_min_down_severity'], 'excluded_downtimes' => $this->sla['excluded_downtimes'] ] ]; @@ -132,6 +133,7 @@ class CControllerSlaEdit extends CController { ], 'description' => $defaults['description'], 'status' => ZBX_SLA_STATUS_ENABLED, + 'og_min_down_severity' => $defaults['og_min_down_severity'], 'excluded_downtimes' => [] ] ]; diff --git a/ui/app/controllers/CControllerSlaUpdate.php b/ui/app/controllers/CControllerSlaUpdate.php index b1ec19b9698..def982c1537 100644 --- a/ui/app/controllers/CControllerSlaUpdate.php +++ b/ui/app/controllers/CControllerSlaUpdate.php @@ -39,6 +39,7 @@ class CControllerSlaUpdate extends CControllerSlaCreateUpdate { 'service_tags' => 'required|array', 'description' => 'required|string', 'status' => 'in '.ZBX_SLA_STATUS_ENABLED, + 'og_min_down_severity' => 'in '.implode(',', range(0, 5)), 'excluded_downtimes' => 'array' ]; @@ -105,7 +106,7 @@ class CControllerSlaUpdate extends CControllerSlaCreateUpdate { 'excluded_downtimes' => [] ]; - $fields = ['slaid', 'name', 'slo', 'period', 'timezone', 'description', 'excluded_downtimes']; + $fields = ['slaid', 'name', 'slo', 'period', 'timezone', 'description', 'og_min_down_severity', 'excluded_downtimes']; $this->getInputs($sla, $fields); diff --git a/ui/app/views/sla.edit.php b/ui/app/views/sla.edit.php index 524b7d52114..69fd98c7402 100644 --- a/ui/app/views/sla.edit.php +++ b/ui/app/views/sla.edit.php @@ -64,6 +64,18 @@ $sla_tab = (new CFormGrid()) ' %' ]) ]) + ->addItem([ + new CLabel(_('Minimum severity for downtime'), 'og_min_down_severity'), + new CFormField( + (new CSelect('og_min_down_severity')) + ->setId('og_min_down_severity') + ->setValue((int) $data['form']['og_min_down_severity']) + ->addOptions(array_map( + fn(int $s) => new CSelectOption($s, CSeverityHelper::getName($s)), + range(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_DISASTER) + )) + ) + ]) ->addItem([ new CLabel(_('Reporting period')), new CFormField( diff --git a/ui/include/classes/api/services/CSla.php b/ui/include/classes/api/services/CSla.php index b87e0892f61..0611adb0173 100644 --- a/ui/include/classes/api/services/CSla.php +++ b/ui/include/classes/api/services/CSla.php @@ -49,20 +49,20 @@ class CSla extends CApiService { 'operator' => ['type' => API_INT32, 'in' => implode(',', [TAG_OPERATOR_LIKE, TAG_OPERATOR_EQUAL, TAG_OPERATOR_NOT_LIKE, TAG_OPERATOR_NOT_EQUAL, TAG_OPERATOR_EXISTS, TAG_OPERATOR_NOT_EXISTS])] ]], 'serviceids' => ['type' => API_IDS, 'flags' => API_ALLOW_NULL | API_NORMALIZE, 'default' => null], - 'filter' => ['type' => API_FILTER, 'flags' => API_ALLOW_NULL, 'default' => null, 'fields' => ['slaid', 'name', 'period', 'slo', 'effective_date', 'timezone', 'status']], + 'filter' => ['type' => API_FILTER, 'flags' => API_ALLOW_NULL, 'default' => null, 'fields' => ['slaid', 'name', 'period', 'slo', 'effective_date', 'timezone', 'status', 'og_min_down_severity']], 'search' => ['type' => API_FILTER, 'flags' => API_ALLOW_NULL, 'default' => null, 'fields' => ['name', 'timezone', 'description']], 'searchByAny' => ['type' => API_BOOLEAN, 'default' => false], 'startSearch' => ['type' => API_FLAG, 'default' => false], 'excludeSearch' => ['type' => API_FLAG, 'default' => false], 'searchWildcardsEnabled' => ['type' => API_BOOLEAN, 'default' => false], // output - 'output' => ['type' => API_OUTPUT, 'in' => implode(',', ['slaid', 'name', 'period', 'slo', 'effective_date', 'timezone', 'status', 'description']), 'default' => API_OUTPUT_EXTEND], + 'output' => ['type' => API_OUTPUT, 'in' => implode(',', ['slaid', 'name', 'period', 'slo', 'effective_date', 'timezone', 'status', 'description', 'og_min_down_severity']), 'default' => API_OUTPUT_EXTEND], 'countOutput' => ['type' => API_FLAG, 'default' => false], 'selectServiceTags' => ['type' => API_OUTPUT, 'flags' => API_ALLOW_NULL | API_ALLOW_COUNT, 'in' => implode(',', ['tag', 'operator', 'value']), 'default' => null], 'selectSchedule' => ['type' => API_OUTPUT, 'flags' => API_ALLOW_NULL | API_ALLOW_COUNT, 'in' => implode(',', ['period_from', 'period_to']), 'default' => null], 'selectExcludedDowntimes' => ['type' => API_OUTPUT, 'flags' => API_ALLOW_NULL | API_ALLOW_COUNT, 'in' => implode(',', ['name', 'period_from', 'period_to']), 'default' => null], // sort and limit - 'sortfield' => ['type' => API_STRINGS_UTF8, 'flags' => API_NORMALIZE, 'in' => implode(',', ['slaid', 'name', 'period', 'slo', 'effective_date', 'timezone', 'status', 'description']), 'uniq' => true, 'default' => []], + 'sortfield' => ['type' => API_STRINGS_UTF8, 'flags' => API_NORMALIZE, 'in' => implode(',', ['slaid', 'name', 'period', 'slo', 'effective_date', 'timezone', 'status', 'description', 'og_min_down_severity']), 'uniq' => true, 'default' => []], 'sortorder' => ['type' => API_SORTORDER, 'default' => []], 'limit' => ['type' => API_INT32, 'flags' => API_ALLOW_NULL, 'in' => '1:'.ZBX_MAX_INT32, 'default' => null], // flags @@ -158,6 +158,7 @@ class CSla extends CApiService { 'timezone' => ['type' => API_STRING_UTF8, 'flags' => API_REQUIRED, 'in' => implode(',', array_merge([ZBX_DEFAULT_TIMEZONE], array_keys(CTimezoneHelper::getList()))), 'length' => DB::getFieldLength('sla', 'timezone')], 'status' => ['type' => API_INT32, 'in' => implode(',', [ZBX_SLA_STATUS_DISABLED, ZBX_SLA_STATUS_ENABLED])], 'description' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('sla', 'description')], + 'og_min_down_severity' => ['type' => API_INT32, 'in' => implode(',', range(0, 5)), 'default' => DB::getDefault('sla', 'og_min_down_severity')], 'service_tags' => ['type' => API_OBJECTS, 'flags' => API_REQUIRED | API_NOT_EMPTY, 'uniq' => [['tag', 'value']], 'fields' => [ 'tag' => ['type' => API_STRING_UTF8, 'flags' => API_REQUIRED | API_NOT_EMPTY, 'length' => DB::getFieldLength('sla_service_tag', 'tag')], 'operator' => ['type' => API_INT32, 'in' => implode(',', [ZBX_SLA_SERVICE_TAG_OPERATOR_EQUAL, ZBX_SLA_SERVICE_TAG_OPERATOR_LIKE]), 'default' => DB::getDefault('sla_service_tag', 'operator')], @@ -236,6 +237,7 @@ class CSla extends CApiService { 'timezone' => ['type' => API_STRING_UTF8, 'in' => implode(',', array_merge([ZBX_DEFAULT_TIMEZONE], array_keys(CTimezoneHelper::getList()))), 'length' => DB::getFieldLength('sla', 'timezone')], 'status' => ['type' => API_INT32, 'in' => implode(',', [ZBX_SLA_STATUS_DISABLED, ZBX_SLA_STATUS_ENABLED])], 'description' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('sla', 'description')], + 'og_min_down_severity' => ['type' => API_INT32, 'in' => implode(',', range(0, 5))], 'service_tags' => ['type' => API_OBJECTS, 'flags' => API_NOT_EMPTY, 'uniq' => [['tag', 'value']], 'fields' => [ 'tag' => ['type' => API_STRING_UTF8, 'flags' => API_REQUIRED | API_NOT_EMPTY, 'length' => DB::getFieldLength('sla_service_tag', 'tag')], 'operator' => ['type' => API_INT32, 'in' => implode(',', [ZBX_SLA_SERVICE_TAG_OPERATOR_EQUAL, ZBX_SLA_SERVICE_TAG_OPERATOR_LIKE]), 'default' => DB::getDefault('sla_service_tag', 'operator')], @@ -1058,7 +1060,7 @@ class CSla extends CApiService { } $db_sla = $this->get([ - 'output' => ['period', 'slo', 'timezone', 'effective_date'], + 'output' => ['period', 'slo', 'timezone', 'effective_date', 'og_min_down_severity'], 'selectSchedule' => ['period_from', 'period_to'], 'selectExcludedDowntimes' => ['name', 'period_from', 'period_to'], 'slaids' => $options['slaid'] @@ -1324,7 +1326,9 @@ class CSla extends CApiService { } } - if ($prev_value == ZBX_SEVERITY_OK) { + // ZBX_SEVERITY_OK is -1; with default threshold 0, only OK counts as uptime + // (preserving original behavior). Higher thresholds treat lower severities as uptime. + if ($prev_value == ZBX_SEVERITY_OK || $prev_value < $db_sla['og_min_down_severity']) { $cell['uptime'] += $uptime; } else { diff --git a/ui/include/schema.inc.php b/ui/include/schema.inc.php index a272bc1a430..dc7135668b7 100644 --- a/ui/include/schema.inc.php +++ b/ui/include/schema.inc.php @@ -8929,6 +8929,12 @@ return [ 'type' => DB::FIELD_TYPE_TEXT, 'length' => 65535, 'default' => '' + ], + 'og_min_down_severity' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_INT, + 'length' => 10, + 'default' => '0' ] ] ],