Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CServiceHelper.php « helpers « classes « include « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 112a0b4cdd448c54b4fe52e0eed1da5a88f61952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php declare(strict_types = 1);
/*
** Zabbix
** Copyright (C) 2001-2021 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/


class CServiceHelper {

	public static function getAlgorithmNames(): array {
		return [
			ZBX_SERVICE_STATUS_CALC_MOST_CRITICAL_ONE => _('Most critical of child services'),
			ZBX_SERVICE_STATUS_CALC_MOST_CRITICAL_ALL => _('Most critical if all children have problems'),
			ZBX_SERVICE_STATUS_CALC_SET_OK => _('Set status to OK')
		];
	}

	public static function getStatusRuleTypeOptions(): array {
		return [
			ZBX_SERVICE_STATUS_RULE_TYPE_N_GE => _s(
				'If at least %2$s child services have %1$s status or above',
				(new CSpan(_('Status')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER),
				(new CSpan(_('N')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER)
			),
			ZBX_SERVICE_STATUS_RULE_TYPE_NP_GE => _s(
				'If at least %2$s of child services have %1$s status or above',
				(new CSpan(_('Status')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER),
				(new CSpan(_('N%')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER)
			),
			ZBX_SERVICE_STATUS_RULE_TYPE_N_L => _s(
				'If less than %2$s child services have %1$s status or below',
				(new CSpan(_('Status')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER),
				(new CSpan(_('N')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER)
			),
			ZBX_SERVICE_STATUS_RULE_TYPE_NP_L => _s(
				'If less than %2$s of child services have %1$s status or below',
				(new CSpan(_('Status')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER),
				(new CSpan(_('N%')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER)
			),
			ZBX_SERVICE_STATUS_RULE_TYPE_W_GE => _s(
				'If weight of child services with %1$s status or above is at least %2$s',
				(new CSpan(_('Status')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER),
				(new CSpan(_('W')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER)
			),
			ZBX_SERVICE_STATUS_RULE_TYPE_WP_GE => _s(
				'If weight of child services with %1$s status or above is at least %2$s',
				(new CSpan(_('Status')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER),
				(new CSpan(_('N%')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER)
			),
			ZBX_SERVICE_STATUS_RULE_TYPE_W_L => _s(
				'If weight of child services with %1$s status or below is less than %2$s',
				(new CSpan(_('Status')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER),
				(new CSpan(_('W')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER)
			),
			ZBX_SERVICE_STATUS_RULE_TYPE_WP_L => _s(
				'If weight of child services with %1$s status or below is less than %2$s',
				(new CSpan(_('Status')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER),
				(new CSpan(_('N%')))->addClass(ZBX_STYLE_TEXT_PLACEHOLDER)
			)
		];
	}

	public static function formatStatusRuleType(int $type, int $new_status, int $number, int $status): ?CObject {
		$status = self::getStatusNames()[$status];

		switch ($type) {
			case ZBX_SERVICE_STATUS_RULE_TYPE_N_GE:
				$rule = _n(
					'If at least %2$s child service has %1$s status or above',
					'If at least %2$s child services have %1$s status or above',
					new CTag('em', true, $status), new CTag('em', true, $number), $number
				);
				break;
			case ZBX_SERVICE_STATUS_RULE_TYPE_NP_GE:
				$rule = _s('If at least %2$s of child services have %1$s status or above',
					new CTag('em', true, $status), new CTag('em', true, [$number, '%']), $number
				);
				break;
			case ZBX_SERVICE_STATUS_RULE_TYPE_N_L:
				$rule = _n(
					'If less than %2$s child service has %1$s status or below',
					'If less than %2$s child services have %1$s status or below',
					new CTag('em', true, $status), new CTag('em', true, $number), $number
				);
				break;
			case ZBX_SERVICE_STATUS_RULE_TYPE_NP_L:
				$rule = _s('If less than %2$s of child services have %1$s status or below',
					new CTag('em', true, $status), new CTag('em', true, [$number, '%']), $number
				);
				break;
			case ZBX_SERVICE_STATUS_RULE_TYPE_W_GE:
				$rule = _s('If weight of child services with %1$s status or above is at least %2$s',
					new CTag('em', true, $status), new CTag('em', true, $number));
				break;
			case ZBX_SERVICE_STATUS_RULE_TYPE_WP_GE:
				$rule = _s('If weight of child services with %1$s status or above is at least %2$s',
					new CTag('em', true, $status), new CTag('em', true, $number).'%');
				break;
			case ZBX_SERVICE_STATUS_RULE_TYPE_W_L:
				$rule = _s('If weight of child services with %1$s status or below is less than %2$s',
					new CTag('em', true, $status), new CTag('em', true, $number));
				break;
			case ZBX_SERVICE_STATUS_RULE_TYPE_WP_L:
				$rule = _s('If weight of child services with %1$s status or below is less than %2$s',
					new CTag('em', true, $status), new CTag('em', true, $number).'%');
				break;
			default:
				$rule = null;
		}

		return $rule !== null
			? new CObject([new CTag('em', true, self::getProblemStatusNames()[$new_status]), ' - ', $rule])
			: null;
	}

	public static function getStatusNames(): array {
		return [ZBX_SEVERITY_OK => _('OK')] + self::getProblemStatusNames();
	}

	public static function getProblemStatusNames(): array {
		$status_names = [];

		foreach (CSeverityHelper::getSeverities() as $severity) {
			$status_names[$severity['value']] = $severity['name'];
		}

		return $status_names;
	}

	public static function getStatusPropagationNames(): array {
		return [
			ZBX_SERVICE_STATUS_PROPAGATION_AS_IS => _('As is'),
			ZBX_SERVICE_STATUS_PROPAGATION_INCREASE => _('Increase by'),
			ZBX_SERVICE_STATUS_PROPAGATION_DECREASE => _('Decrease by'),
			ZBX_SERVICE_STATUS_PROPAGATION_IGNORE => _('Ignore this service'),
			ZBX_SERVICE_STATUS_PROPAGATION_FIXED => _('Fixed status')
		];
	}
}