1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
serversdata.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Scale;
4
9
class
ServersData
10
{
11
protected
static
$bxInfo
=
array
();
//wrapper_ansible_conf -a bx_info -H hostname
12
18
public
static
function
getServer
($hostname)
19
{
20
if
($hostname ==
''
)
21
throw
new \Bitrix\Main\ArgumentNullException(
"hostname"
);
22
23
$result
=
array
();
24
$servers =
self::getList
();
25
26
if
(isset($servers[$hostname]))
27
$result
= $servers[$hostname];
28
29
return
$result
;
30
}
31
35
public
static
function
getList
()
36
{
37
$result
=
array
();
38
$shellAdapter =
new
ShellAdapter
();
39
$execRes = $shellAdapter->syncExec(
"sudo -u root /opt/webdir/bin/wrapper_ansible_conf -o json"
);
40
$serversData = $shellAdapter->getLastOutput();
41
42
if
($execRes)
43
{
44
$arData = json_decode($serversData,
true
);
45
46
//mgmt server must be first
47
if
(isset($arData[
"params"
]) && is_array($arData[
"params"
]))
48
{
49
foreach
($arData[
"params"
] as $hostname => $server)
50
{
51
try
52
{
53
$server[
"BX_ENV_VER"
] = static::getBxEnvVer($hostname);
54
$bxInfo
= static::getBxInfo($hostname);
55
$server[
"BX_INFO"
] =
$bxInfo
;
56
57
if
(isset(
$bxInfo
[
"bx_last_password_change"
]))
58
$server[
"LAST_PASSWORD_CHANGE"
] =
$bxInfo
[
"bx_last_password_change"
];
59
60
if
(!$server[
"BX_ENV_VER"
] || !Helper::checkBxEnvVersion($server[
"BX_ENV_VER"
]))
61
$server[
"BX_ENV_NEED_UPDATE"
] =
true
;
62
else
63
$server[
"BX_ENV_NEED_UPDATE"
] =
false
;
64
65
}
66
catch
(
ServerBxInfoException
$e)
67
{
68
$server[
"BX_INFO_ERROR"
] = $e->getMessage();
69
}
70
71
$result
[$hostname] = $server;
72
}
73
74
\sortByColumn
(
$result
,
array
(
"host_id"
=>
array
(SORT_NUMERIC, SORT_ASC)));
75
}
76
}
77
78
return
$result
;
79
}
80
86
public
static
function
getServerRoles
($hostname)
87
{
88
if
($hostname ==
''
)
89
throw
new \Bitrix\Main\ArgumentNullException(
"hostname"
);
90
91
$result
=
array
();
92
$server = static::getServer($hostname);
93
94
if
(isset($server[
"roles"
]))
95
$result
= $server[
"roles"
];
96
97
$result
[
"SERVER"
] =
array
();
98
99
return
$result
;
100
}
101
102
public
static
function
getDbList
($hostname)
103
{
104
if
($hostname ==
''
)
105
throw
new \Bitrix\Main\ArgumentNullException(
"hostname"
);
106
107
$dbList =
array
();
108
109
$action
=
new
Action
(
"get_db_list"
,
array
(
110
"START_COMMAND_TEMPLATE"
=>
"sudo -u root /opt/webdir/bin/wrapper_ansible_conf -a dbs_list -H "
.$hostname.
" -o json"
,
111
"LOG_LEVEL"
=>
Logger::LOG_LEVEL_DISABLE
112
),
113
""
,
114
array
()
115
);
116
117
$action
->start();
118
$actRes =
$action
->getResult();
119
120
if
(isset($actRes[
"get_db_list"
][
"OUTPUT"
][
"DATA"
][
"params"
][
"dbs_list"
][$hostname][
"dbs_list"
]))
121
$dbList = $actRes[
"get_db_list"
][
"OUTPUT"
][
"DATA"
][
"params"
][
"dbs_list"
][$hostname][
"dbs_list"
];
122
123
if
(is_array($dbList))
124
$result
= $dbList;
125
else
126
$result
=
array
();
127
128
return
$result
;
129
}
130
137
protected
static
function
getBxInfo
($hostname)
138
{
139
if
($hostname ==
''
)
140
throw
new \Bitrix\Main\ArgumentNullException(
"hostname"
);
141
142
$result
=
array
();
143
144
if
(isset(static::$bxInfo[$hostname]))
145
{
146
$result
= static::$bxInfo[$hostname];
147
}
148
else
149
{
150
$action
=
new
Action
(
"get_bx_info"
,
array
(
151
"START_COMMAND_TEMPLATE"
=>
"sudo -u root /opt/webdir/bin/wrapper_ansible_conf -a bx_info -H "
.$hostname.
" -o json"
,
152
"LOG_LEVEL"
=>
Logger::LOG_LEVEL_DISABLE
153
),
154
""
,
155
array
()
156
);
157
158
$action
->start();
159
$actRes =
$action
->getResult();
160
161
if
(isset($actRes[
"get_bx_info"
][
"OUTPUT"
][
"DATA"
][
"params"
][
"bx_variables"
][$hostname]))
162
{
163
$result
= static::$bxInfo[$hostname] = $actRes[
"get_bx_info"
][
"OUTPUT"
][
"DATA"
][
"params"
][
"bx_variables"
][$hostname];
164
}
165
elseif
(isset($actRes[
"get_bx_info"
][
"RESULT"
])
166
&& $actRes[
"get_bx_info"
][
"RESULT"
] =
"ERROR"
167
&& $actRes[
"get_bx_info"
][
"ERROR"
] <>
''
168
)
169
{
170
throw
new \Bitrix\Scale\ServerBxInfoException($actRes[
"get_bx_info"
][
"ERROR"
], $hostname);
171
}
172
}
173
174
return
$result
;
175
}
176
182
public
static
function
getBxEnvVer
($hostname)
183
{
184
if
($hostname ==
''
)
185
throw
new \Bitrix\Main\ArgumentNullException(
"hostname"
);
186
187
$bxInfo
= static::getBxInfo($hostname);
188
189
if
(isset(
$bxInfo
[
"bx_version"
])
190
&&
$bxInfo
[
"bx_version"
] !=
"0"
191
)
192
{
193
$result
=
$bxInfo
[
"bx_version"
];
194
}
195
else
196
{
197
$result
=
false
;
198
}
199
200
return
$result
;
201
}
202
203
public
static
function
getGraphCategories
($hostname)
204
{
205
$result
=
array
();
206
$roles = static::getServerRoles($hostname);
207
208
foreach
($roles as $roleId => $role)
209
$result
= array_merge(
$result
, \
Bitrix
\
Scale
\
RolesData::getGraphsCategories
($roleId));
210
211
return
$result
;
212
}
213
214
public
static
function
getDbMasterHostname
()
215
{
216
$servers = static::getList();
217
218
foreach
($servers as $hostname => $server)
219
if
(isset($server[
"roles"
][
"mysql"
][
"type"
]) && $server[
"roles"
][
"mysql"
][
"type"
] ==
"master"
)
220
return
$hostname;
221
222
return
false
;
223
}
224
}
Bitrix\Scale\Action
Определения
action.php:13
Bitrix\Scale\Logger\LOG_LEVEL_DISABLE
const LOG_LEVEL_DISABLE
Определения
logger.php:14
Bitrix\Scale\RolesData\getGraphsCategories
static getGraphsCategories($roleId)
Определения
rolesdata.php:62
Bitrix\Scale\ServerBxInfoException
Определения
exceptions.php:10
Bitrix\Scale\ServersData
Определения
serversdata.php:10
Bitrix\Scale\ServersData\getDbMasterHostname
static getDbMasterHostname()
Определения
serversdata.php:214
Bitrix\Scale\ServersData\getGraphCategories
static getGraphCategories($hostname)
Определения
serversdata.php:203
Bitrix\Scale\ServersData\getBxInfo
static getBxInfo($hostname)
Определения
serversdata.php:137
Bitrix\Scale\ServersData\getServer
static getServer($hostname)
Определения
serversdata.php:18
Bitrix\Scale\ServersData\getServerRoles
static getServerRoles($hostname)
Определения
serversdata.php:86
Bitrix\Scale\ServersData\getBxEnvVer
static getBxEnvVer($hostname)
Определения
serversdata.php:182
Bitrix\Scale\ServersData\getDbList
static getDbList($hostname)
Определения
serversdata.php:102
Bitrix\Scale\ServersData\getList
static getList()
Определения
serversdata.php:35
Bitrix\Scale\ServersData\$bxInfo
static $bxInfo
Определения
serversdata.php:11
Bitrix\Scale\ShellAdapter
Определения
shelladapter.php:10
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
sortByColumn
sortByColumn(array &$array, $columns, $callbacks='', $defaultValueIfNotSetValue=null, $preserveKeys=false)
Определения
tools.php:5087
Bitrix\Scale
Определения
action.php:2
Bitrix
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$action
$action
Определения
file_dialog.php:21
bitrix
modules
scale
lib
serversdata.php
Создано системой
1.14.0