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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2019 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.
**/
$widget = (new CWidget())->setTitle(_('Item prototypes'));
if (!empty($this->data['hostid'])) {
$widget->addItem(get_header_host_table('items', $this->data['hostid'], $this->data['parent_discoveryid']));
}
// create form
$itemForm = (new CForm())
->setName('itemForm')
->setAttribute('aria-labeledby', ZBX_STYLE_PAGE_TITLE)
->addVar('form', $this->data['form'])
->addVar('parent_discoveryid', $this->data['parent_discoveryid']);
if (!empty($this->data['itemid'])) {
$itemForm->addVar('itemid', $this->data['itemid']);
}
// create form list
$itemFormList = new CFormList('itemFormList');
if (!empty($this->data['templates'])) {
$itemFormList->addRow(_('Parent items'), $this->data['templates']);
}
$readonly = false;
if ($data['limited']) {
$readonly = true;
}
$itemFormList->addRow(
(new CLabel(_('Name'), 'name'))->setAsteriskMark(),
(new CTextBox('name', $this->data['name'], $readonly))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired()
->setAttribute('autofocus', 'autofocus')
);
// append type to form list
if ($readonly) {
$itemForm->addVar('type', $this->data['type']);
$itemFormList->addRow((new CLabel(_('Type'), 'typename')),
(new CTextBox('typename', item_type2str($this->data['type']), true))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
);
}
else {
$itemFormList->addRow((new CLabel(_('Type'), 'type')),
(new CComboBox('type', $this->data['type'], null, $this->data['types']))
);
}
// append key to form list
$key_controls = [
(new CTextBox('key', $this->data['key'], $readonly))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired()
];
if (!$readonly) {
$key_controls[] = (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN);
$key_controls[] = (new CButton('keyButton', _('Select')))
->addClass(ZBX_STYLE_BTN_GREY)
->onClick('return PopUp("popup.generic",jQuery.extend('.
CJs::encodeJson([
'srctbl' => 'help_items',
'srcfld1' => 'key',
'dstfrm' => $itemForm->getName(),
'dstfld1' => 'key'
]).
',{itemtype: jQuery("#type option:selected").val()}), null, this);'
);
}
$itemFormList->addRow((new CLabel(_('Key'), 'key'))->setAsteriskMark(), $key_controls);
// ITEM_TYPE_HTTPAGENT URL field.
$itemFormList->addRow(
(new CLabel(_('URL'), 'url'))->setAsteriskMark(),
[
(new CTextBox('url', $data['url'], $readonly, DB::getFieldLength('items', 'url')))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired(),
(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
(new CButton('httpcheck_parseurl', _('Parse')))
->setEnabled(!$readonly)
->addClass(ZBX_STYLE_BTN_GREY)
->setAttribute('data-action', 'parse_url')
],
'url_row'
);
// ITEM_TYPE_HTTPAGENT Query fields.
$query_fields_data = [];
if (is_array($data['query_fields']) && $data['query_fields']) {
foreach ($data['query_fields'] as $pair) {
$query_fields_data[] = ['name' => key($pair), 'value' => reset($pair)];
}
}
elseif (!$readonly) {
$query_fields_data[] = ['name' => '', 'value' => ''];
}
$query_fields = (new CTag('script', true))->setAttribute('type', 'text/json');
$query_fields->items = [CJs::encodeJson($query_fields_data)];
$itemFormList->addRow(
new CLabel(_('Query fields'), 'query_fields_pairs'),
(new CDiv([
(new CTable())
->setAttribute('style', 'width: 100%;')
->setHeader(['', _('Name'), '', _('Value'), ''])
->addRow((new CRow)->setAttribute('data-insert-point', 'append'))
->setFooter(new CRow(
(new CCol(
(new CButton(null, _('Add')))
->setEnabled(!$readonly)
->addClass(ZBX_STYLE_BTN_LINK)
->setAttribute('data-row-action', 'add_row')
))->setColSpan(5)
)),
(new CTag('script', true))
->setAttribute('type', 'text/x-jquery-tmpl')
->addItem(new CRow([
(new CCol((new CDiv)->addClass(ZBX_STYLE_DRAG_ICON)))->addClass(ZBX_STYLE_TD_DRAG_ICON),
(new CTextBox('query_fields[name][#{index}]', '#{name}', $readonly))
->setAttribute('placeholder', _('name'))
->setWidth(ZBX_TEXTAREA_TAG_WIDTH),
'⇒',
(new CTextBox('query_fields[value][#{index}]', '#{value}', $readonly))
->setAttribute('placeholder', _('value'))
->setWidth(ZBX_TEXTAREA_TAG_WIDTH),
(new CButton(null, _('Remove')))
->setEnabled(!$readonly)
->addClass(ZBX_STYLE_BTN_LINK)
->setAttribute('data-row-action', 'remove_row')
])),
$query_fields
]))
->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
->setId('query_fields_pairs')
->setAttribute('data-sortable-pairs-table', $readonly ? '0': '1')
->setAttribute('style', 'min-width: '.ZBX_TEXTAREA_BIG_WIDTH . 'px;'),
'query_fields_row'
);
// ITEM_TYPE_HTTPAGENT Request type.
$itemFormList->addRow(
new CLabel(_('Request type'), 'request_method'),
[
$readonly ? new CVar('request_method', $data['request_method']) : null,
(new CComboBox($readonly ? '' : 'request_method', $data['request_method'], null, [
HTTPCHECK_REQUEST_GET => 'GET',
HTTPCHECK_REQUEST_POST => 'POST',
HTTPCHECK_REQUEST_PUT => 'PUT',
HTTPCHECK_REQUEST_HEAD => 'HEAD'
]))->setEnabled(!$readonly)
],
'request_method_row'
);
// ITEM_TYPE_HTTPAGENT Timeout field.
$itemFormList->addRow(
new CLabel(_('Timeout'), 'timeout'),
(new CTextBox('timeout', $data['timeout'], $readonly))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH),
'timeout_row'
);
// ITEM_TYPE_HTTPAGENT Request body type.
$itemFormList->addRow(
new CLabel(_('Request body type'), 'post_type'),
(new CRadioButtonList('post_type', (int) $data['post_type']))
->addValue(_('Raw data'), ZBX_POSTTYPE_RAW)
->addValue(_('JSON data'), ZBX_POSTTYPE_JSON)
->addValue(_('XML data'), ZBX_POSTTYPE_XML)
->setEnabled(!$readonly)
->setModern(true),
'post_type_row'
);
// ITEM_TYPE_HTTPAGENT Request body.
$itemFormList->addRow(
new CLabel(_('Request body'), 'posts'),
(new CTextArea('posts', $data['posts'], compact('readonly')))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'posts_row'
);
// ITEM_TYPE_HTTPAGENT Headers fields.
$headers_data = [];
if (is_array($data['headers']) && $data['headers']) {
foreach ($data['headers'] as $pair) {
$headers_data[] = ['name' => key($pair), 'value' => reset($pair)];
}
}
elseif (!$readonly) {
$headers_data[] = ['name' => '', 'value' => ''];
}
$headers = (new CTag('script', true))->setAttribute('type', 'text/json');
$headers->items = [CJs::encodeJson($headers_data)];
$itemFormList->addRow(
new CLabel(_('Headers'), 'headers_pairs'),
(new CDiv([
(new CTable())
->setAttribute('style', 'width: 100%;')
->setHeader(['', _('Name'), '', _('Value'), ''])
->addRow((new CRow)->setAttribute('data-insert-point', 'append'))
->setFooter(new CRow(
(new CCol(
(new CButton(null, _('Add')))
->addClass(ZBX_STYLE_BTN_LINK)
->setEnabled(!$readonly)
->setAttribute('data-row-action', 'add_row')
))->setColSpan(5)
)),
(new CTag('script', true))
->setAttribute('type', 'text/x-jquery-tmpl')
->addItem(new CRow([
(new CCol((new CDiv)->addClass(ZBX_STYLE_DRAG_ICON)))->addClass(ZBX_STYLE_TD_DRAG_ICON),
(new CTextBox('headers[name][#{index}]', '#{name}', $readonly))
->setAttribute('placeholder', _('name'))
->setWidth(ZBX_TEXTAREA_TAG_WIDTH),
'⇒',
(new CTextBox('headers[value][#{index}]', '#{value}', $readonly))
->setAttribute('placeholder', _('value'))
->setWidth(ZBX_TEXTAREA_TAG_WIDTH),
(new CButton(null, _('Remove')))
->addClass(ZBX_STYLE_BTN_LINK)
->setEnabled(!$readonly)
->setAttribute('data-row-action', 'remove_row')
])),
$headers
]))
->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
->setId('headers_pairs')
->setAttribute('data-sortable-pairs-table', $readonly ? '0': '1')
->setAttribute('style', 'min-width: '.ZBX_TEXTAREA_BIG_WIDTH . 'px;'),
'headers_row'
);
// ITEM_TYPE_HTTPAGENT Required status codes.
$itemFormList->addRow(
new CLabel(_('Required status codes'), 'status_codes'),
(new CTextBox('status_codes', $data['status_codes'], $readonly))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'status_codes_row'
);
// ITEM_TYPE_HTTPAGENT Follow redirects.
$itemFormList->addRow(
new CLabel(_('Follow redirects'), 'follow_redirects'),
(new CCheckBox('follow_redirects', HTTPTEST_STEP_FOLLOW_REDIRECTS_ON))
->setEnabled(!$readonly)
->setChecked($data['follow_redirects'] == HTTPTEST_STEP_FOLLOW_REDIRECTS_ON),
'follow_redirects_row'
);
// ITEM_TYPE_HTTPAGENT Retrieve mode.
$itemFormList->addRow(
new CLabel(_('Retrieve mode'), 'retrieve_mode'),
(new CRadioButtonList('retrieve_mode', (int) $data['retrieve_mode']))
->addValue(_('Body'), HTTPTEST_STEP_RETRIEVE_MODE_CONTENT)
->addValue(_('Headers'), HTTPTEST_STEP_RETRIEVE_MODE_HEADERS)
->addValue(_('Body and headers'), HTTPTEST_STEP_RETRIEVE_MODE_BOTH)
->setEnabled(!($readonly || $data['request_method'] == HTTPCHECK_REQUEST_HEAD))
->setModern(true),
'retrieve_mode_row'
);
// ITEM_TYPE_HTTPAGENT Convert to JSON.
$itemFormList->addRow(
new CLabel(_('Convert to JSON'), 'output_format'),
(new CCheckBox('output_format', HTTPCHECK_STORE_JSON))
->setEnabled(!$readonly)
->setChecked($data['output_format'] == HTTPCHECK_STORE_JSON),
'output_format_row'
);
// ITEM_TYPE_HTTPAGENT HTTP proxy.
$itemFormList->addRow(
new CLabel(_('HTTP proxy'), 'http_proxy'),
(new CTextBox('http_proxy', $data['http_proxy'], $readonly, DB::getFieldLength('items', 'http_proxy')))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAttribute('placeholder', 'http://[user[:password]@]proxy.example.com[:port]'),
'http_proxy_row'
);
// ITEM_TYPE_HTTPAGENT HTTP authentication.
$itemFormList->addRow(
new CLabel(_('HTTP authentication'), 'http_authtype'),
[
$readonly ? new CVar('http_authtype', $data['http_authtype']) : null,
(new CComboBox($readonly ? '' : 'http_authtype', $data['http_authtype'], null, [
HTTPTEST_AUTH_NONE => _('None'),
HTTPTEST_AUTH_BASIC => _('Basic'),
HTTPTEST_AUTH_NTLM => _('NTLM')
]))->setEnabled(!$readonly)
],
'http_authtype_row'
);
// ITEM_TYPE_HTTPAGENT User name.
$itemFormList->addRow(
(new CLabel(_('User name'), 'http_username'))->setAsteriskMark(),
(new CTextBox('http_username', $data['http_username'], $readonly, DB::getFieldLength('items', 'username')))
->setAriaRequired()
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'http_username_row'
);
// ITEM_TYPE_HTTPAGENT Password.
$itemFormList->addRow(
(new CLabel(_('Password'), 'http_password'))->setAsteriskMark(),
(new CTextBox('http_password', $data['http_password'], $readonly, DB::getFieldLength('items', 'password')))
->setAriaRequired()
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'http_password_row'
);
// ITEM_TYPE_HTTPAGENT SSL verify peer.
$itemFormList->addRow(
new CLabel(_('SSL verify peer'), 'verify_peer'),
(new CCheckBox('verify_peer', HTTPTEST_VERIFY_PEER_ON))
->setEnabled(!$readonly)
->setChecked($data['verify_peer'] == HTTPTEST_VERIFY_PEER_ON),
'verify_peer_row'
);
// ITEM_TYPE_HTTPAGENT SSL verify host.
$itemFormList->addRow(
new CLabel(_('SSL verify host'), 'verify_host'),
(new CCheckBox('verify_host', HTTPTEST_VERIFY_HOST_ON))
->setEnabled(!$readonly)
->setChecked($data['verify_host'] == HTTPTEST_VERIFY_HOST_ON),
'verify_host_row'
);
// ITEM_TYPE_HTTPAGENT SSL certificate file.
$itemFormList->addRow(
new CLabel(_('SSL certificate file'), 'ssl_cert_file'),
(new CTextBox('ssl_cert_file', $data['ssl_cert_file'], $readonly, DB::getFieldLength('items', 'ssl_cert_file')))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'ssl_cert_file_row'
);
// ITEM_TYPE_HTTPAGENT SSL key file.
$itemFormList->addRow(
new CLabel(_('SSL key file'), 'ssl_key_file'),
(new CTextBox('ssl_key_file', $data['ssl_key_file'], $readonly, DB::getFieldLength('items', 'ssl_key_file')))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'ssl_key_file_row'
);
// ITEM_TYPE_HTTPAGENT SSL key password.
$itemFormList->addRow(
new CLabel(_('SSL key password'), 'ssl_key_password'),
(new CTextBox('ssl_key_password', $data['ssl_key_password'], $readonly,
DB::getFieldLength('items', 'ssl_key_password')
))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'ssl_key_password_row'
);
$master_itemname = ($data['master_itemid'] != 0) ? $data['hostname'].NAME_DELIMITER.$data['master_itemname'] : '';
// Append master item select.
$master_item = [
(new CTextBox('master_itemname', $master_itemname, true))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired(),
(new CVar('master_itemid', $data['master_itemid'], 'master_itemid'))
];
if (!$readonly) {
$master_item[] = (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN);
$master_item[] = (new CButton('button', _('Select')))
->addClass(ZBX_STYLE_BTN_GREY)
->onClick('return PopUp("popup.generic",'.
CJs::encodeJson([
'srctbl' => 'items',
'srcfld1' => 'itemid',
'srcfld2' => 'name',
'dstfrm' => $itemForm->getName(),
'dstfld1' => 'master_itemid',
'dstfld2' => 'master_itemname',
'only_hostid' => $data['hostid'],
'excludeids' => [$data['itemid']],
'with_webitems' => 1,
'normal_only' => 1
]).', null, this);'
);
$master_item[] = (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN);
$master_item[] = (new CButton('button', _('Select prototype')))
->addClass(ZBX_STYLE_BTN_GREY)
->onClick('return PopUp("popup.generic",'.
CJs::encodeJson([
'srctbl' => 'item_prototypes',
'srcfld1' => 'itemid',
'srcfld2' => 'name',
'dstfrm' => $itemForm->getName(),
'dstfld1' => 'master_itemid',
'dstfld2' => 'master_itemname',
'parent_discoveryid' => $data['parent_discoveryid'],
'excludeids' => [$data['itemid']]
]).', null, this);'
);
}
$itemFormList->addRow(
(new CLabel(_('Master item'), 'master_itemname'))->setAsteriskMark(),
$master_item,
'row_master_item'
);
// append interfaces to form list
if (!empty($this->data['interfaces'])) {
$interfacesComboBox = (new CComboBox('interfaceid', $data['interfaceid']))->setAriaRequired();
// Set up interface groups sorted by priority.
$interface_types = zbx_objectValues($this->data['interfaces'], 'type');
$interface_groups = [];
foreach ([INTERFACE_TYPE_AGENT, INTERFACE_TYPE_SNMP, INTERFACE_TYPE_JMX, INTERFACE_TYPE_IPMI] as $interface_type) {
if (in_array($interface_type, $interface_types)) {
$interface_groups[$interface_type] = new COptGroup(interfaceType2str($interface_type));
}
}
// add interfaces to groups
foreach ($this->data['interfaces'] as $interface) {
$option = new CComboItem($interface['interfaceid'],
$interface['useip']
? $interface['ip'].' : '.$interface['port']
: $interface['dns'].' : '.$interface['port'],
($interface['interfaceid'] == $data['interfaceid'])
);
$option->setAttribute('data-interfacetype', $interface['type']);
$interface_groups[$interface['type']]->addItem($option);
}
foreach ($interface_groups as $interface_group) {
$interfacesComboBox->addItem($interface_group);
}
$span = (new CSpan(_('No interface found')))
->addClass(ZBX_STYLE_RED)
->setId('interface_not_defined')
->setAttribute('style', 'display: none;');
$itemFormList->addRow((new CLabel(_('Host interface'), 'interfaceid'))->setAsteriskMark(),
[$interfacesComboBox, $span], 'interface_row'
);
$itemForm->addVar('selectedInterfaceId', $data['interfaceid']);
}
$itemFormList->addRow(
(new CLabel(_('SNMP OID'), 'snmp_oid'))->setAsteriskMark(),
(new CTextBox('snmp_oid', $this->data['snmp_oid'], $readonly, 512))
->setAttribute('placeholder', '[IF-MIB::]ifInOctets.1')
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired(),
'row_snmp_oid'
);
$itemFormList->addRow(_('Context name'),
(new CTextBox('snmpv3_contextname', $this->data['snmpv3_contextname']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'row_snmpv3_contextname'
);
$itemFormList->addRow(
(new CLabel(_('SNMP community'), 'snmp_community'))->setAsteriskMark(),
(new CTextBox('snmp_community', $this->data['snmp_community'], false, 64))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired(),
'row_snmp_community'
);
$itemFormList->addRow(_('Security name'),
(new CTextBox('snmpv3_securityname', $this->data['snmpv3_securityname'], false, 64))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'row_snmpv3_securityname'
);
// append snmpv3 security level to form list
$securityLevelComboBox = new CComboBox('snmpv3_securitylevel', $this->data['snmpv3_securitylevel'], null, [
ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV => 'noAuthNoPriv',
ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV => 'authNoPriv',
ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV => 'authPriv'
]);
$itemFormList->addRow(_('Security level'), $securityLevelComboBox, 'row_snmpv3_securitylevel');
$itemFormList->addRow((new CLabel(_('Authentication protocol'), 'snmpv3_authprotocol')),
(new CRadioButtonList('snmpv3_authprotocol', (int) $this->data['snmpv3_authprotocol']))
->addValue(_('MD5'), ITEM_AUTHPROTOCOL_MD5)
->addValue(_('SHA'), ITEM_AUTHPROTOCOL_SHA)
->setModern(true),
'row_snmpv3_authprotocol'
);
$itemFormList->addRow(_('Authentication passphrase'),
(new CTextBox('snmpv3_authpassphrase', $this->data['snmpv3_authpassphrase'], false, 64))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'row_snmpv3_authpassphrase'
);
$itemFormList->addRow((new CLabel(_('Privacy protocol'), 'snmpv3_privprotocol')),
(new CRadioButtonList('snmpv3_privprotocol', (int) $this->data['snmpv3_privprotocol']))
->addValue(_('DES'), ITEM_PRIVPROTOCOL_DES)
->addValue(_('AES'), ITEM_PRIVPROTOCOL_AES)
->setModern(true),
'row_snmpv3_privprotocol'
);
$itemFormList->addRow(_('Privacy passphrase'),
(new CTextBox('snmpv3_privpassphrase', $this->data['snmpv3_privpassphrase'], false, 64))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'row_snmpv3_privpassphrase'
);
$itemFormList->addRow(_('Port'),
(new CTextBox('port', $this->data['port'], false, 64))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH), 'row_port'
);
$itemFormList->addRow(
(new CLabel(_('IPMI sensor'), 'ipmi_sensor'))->setAsteriskMark(),
(new CTextBox('ipmi_sensor', $this->data['ipmi_sensor'], $readonly, 128))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired(),
'row_ipmi_sensor'
);
// append authentication method to form list
$authTypeComboBox = new CComboBox('authtype', $this->data['authtype'], null, [
ITEM_AUTHTYPE_PASSWORD => _('Password'),
ITEM_AUTHTYPE_PUBLICKEY => _('Public key')
]);
$itemFormList->addRow(_('Authentication method'), $authTypeComboBox, 'row_authtype');
$itemFormList->addRow((new CLabel(_('JMX endpoint'), 'jmx_endpoint'))->setAsteriskMark(),
(new CTextBox('jmx_endpoint', $data['jmx_endpoint'], false, 255))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired(),
'row_jmx_endpoint'
);
$itemFormList->addRow(_('User name'),
(new CTextBox('username', $this->data['username'], false, 64))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH),
'row_username'
);
$itemFormList->addRow(
(new CLabel(_('Public key file'), 'publickey'))->setAsteriskMark(),
(new CTextBox('publickey', $this->data['publickey'], false, 64))
->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
->setAriaRequired(),
'row_publickey'
);
$itemFormList->addRow(
(new CLabel(_('Private key file'), 'privatekey'))->setAsteriskMark(),
(new CTextBox('privatekey', $this->data['privatekey'], false, 64))
->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
->setAriaRequired(),
'row_privatekey'
);
$itemFormList->addRow(_('Password'),
(new CTextBox('password', $this->data['password'], false, 64))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH),
'row_password'
);
$itemFormList->addRow(
(new CLabel(_('Executed script'), 'params_es'))->setAsteriskMark(),
(new CTextArea('params_es', $this->data['params']))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired(),
'label_executed_script'
);
$itemFormList->addRow(
(new CLabel(_('SQL query'), 'params_ap'))->setAsteriskMark(),
(new CTextArea('params_ap', $this->data['params']))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired(),
'label_params'
);
$itemFormList->addRow(
(new CLabel(_('Formula'), 'params_f'))->setAsteriskMark(),
(new CTextArea('params_f', $this->data['params']))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired(),
'label_formula'
);
// append value type to form list
if ($readonly) {
$itemForm->addVar('value_type', $this->data['value_type']);
$itemFormList->addRow((new CLabel(_('Type of information'), 'value_type_name')),
(new CTextBox('value_type_name', itemValueTypeString($this->data['value_type']), true))
->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
);
}
else {
$itemFormList->addRow((new CLabel(_('Type of information'), 'value_type')),
(new CComboBox('value_type', $this->data['value_type'], null, [
ITEM_VALUE_TYPE_UINT64 => _('Numeric (unsigned)'),
ITEM_VALUE_TYPE_FLOAT => _('Numeric (float)'),
ITEM_VALUE_TYPE_STR => _('Character'),
ITEM_VALUE_TYPE_LOG => _('Log'),
ITEM_VALUE_TYPE_TEXT => _('Text')
]))
);
}
$itemFormList->addRow(_('Units'),
(new CTextBox('units', $this->data['units'], $readonly))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'row_units'
);
$itemFormList->addRow((new CLabel(_('Update interval'), 'delay'))->setAsteriskMark(),
(new CTextBox('delay', $data['delay']))
->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
->setAriaRequired(),
'row_delay'
);
// Append delay_flex to form list.
$delayFlexTable = (new CTable())
->setId('delayFlexTable')
->setHeader([_('Type'), _('Interval'), _('Period'), _('Action')])
->setAttribute('style', 'width: 100%;');
foreach ($data['delay_flex'] as $i => $delay_flex) {
$type_input = (new CRadioButtonList('delay_flex['.$i.'][type]', (int) $delay_flex['type']))
->addValue(_('Flexible'), ITEM_DELAY_FLEXIBLE)
->addValue(_('Scheduling'), ITEM_DELAY_SCHEDULING)
->setModern(true);
if ($delay_flex['type'] == ITEM_DELAY_FLEXIBLE) {
$delay_input = (new CTextBox('delay_flex['.$i.'][delay]', $delay_flex['delay']))
->setAttribute('placeholder', ZBX_ITEM_FLEXIBLE_DELAY_DEFAULT);
$period_input = (new CTextBox('delay_flex['.$i.'][period]', $delay_flex['period']))
->setAttribute('placeholder', ZBX_DEFAULT_INTERVAL);
$schedule_input = (new CTextBox('delay_flex['.$i.'][schedule]'))
->setAttribute('placeholder', ZBX_ITEM_SCHEDULING_DEFAULT)
->setAttribute('style', 'display: none;');
}
else {
$delay_input = (new CTextBox('delay_flex['.$i.'][delay]'))
->setAttribute('placeholder', ZBX_ITEM_FLEXIBLE_DELAY_DEFAULT)
->setAttribute('style', 'display: none;');
$period_input = (new CTextBox('delay_flex['.$i.'][period]'))
->setAttribute('placeholder', ZBX_DEFAULT_INTERVAL)
->setAttribute('style', 'display: none;');
$schedule_input = (new CTextBox('delay_flex['.$i.'][schedule]', $delay_flex['schedule']))
->setAttribute('placeholder', ZBX_ITEM_SCHEDULING_DEFAULT);
}
$button = (new CButton('delay_flex['.$i.'][remove]', _('Remove')))
->addClass(ZBX_STYLE_BTN_LINK)
->addClass('element-table-remove');
$delayFlexTable->addRow([$type_input, [$delay_input, $schedule_input], $period_input, $button], 'form_row');
}
$delayFlexTable->addRow([(new CButton('interval_add', _('Add')))
->addClass(ZBX_STYLE_BTN_LINK)
->addClass('element-table-add')]);
$itemFormList->addRow(_('Custom intervals'),
(new CDiv($delayFlexTable))
->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
->setAttribute('style', 'min-width: '.ZBX_TEXTAREA_STANDARD_WIDTH.'px;'),
'row_flex_intervals'
);
$keepHistory = [];
$keepHistory[] = (new CTextBox('history', $data['history']))
->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
->setAriaRequired();
$itemFormList->addRow((new CLabel(_('History storage period'), 'history'))->setAsteriskMark(),
$keepHistory
);
$keepTrend = [];
$keepTrend[] = (new CTextBox('trends', $data['trends']))
->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
->setAriaRequired();
$itemFormList->addRow((new CLabel(_('Trend storage period'), 'trends'))->setAsteriskMark(), $keepTrend,
'row_trends'
);
$itemFormList->addRow(_('Log time format'),
(new CTextBox('logtimefmt', $this->data['logtimefmt'], $readonly, 64))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'row_logtimefmt'
);
// append valuemap to form list
if ($readonly) {
$itemForm->addVar('valuemapid', $this->data['valuemapid']);
$valuemapComboBox = (new CTextBox('valuemap_name',
!empty($this->data['valuemaps']) ? $this->data['valuemaps'] : _('As is'),
true
))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH);
}
else {
$valuemapComboBox = new CComboBox('valuemapid', $this->data['valuemapid']);
$valuemapComboBox->addItem(0, _('As is'));
foreach ($this->data['valuemaps'] as $valuemap) {
$valuemapComboBox->addItem($valuemap['valuemapid'], CHtml::encode($valuemap['name']));
}
}
$link = (new CLink(_('show value mappings'), 'adm.valuemapping.php'))->setAttribute('target', '_blank');
$itemFormList
->addRow(_('Show value'), [$valuemapComboBox, SPACE, $link], 'row_valuemap')
->addRow(
new CLabel(_('Enable trapping'), 'allow_traps'),
(new CCheckBox('allow_traps', HTTPCHECK_ALLOW_TRAPS_ON))
->setChecked($data['allow_traps'] == HTTPCHECK_ALLOW_TRAPS_ON),
'allow_traps_row'
)
->addRow(_('Allowed hosts'),
(new CTextBox('trapper_hosts', $this->data['trapper_hosts']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
'row_trapper_hosts'
)
->addRow(new CLabel(_('New application'), 'new_application'),
(new CSpan(
(new CTextBox('new_application', $this->data['new_application']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
))->addClass(ZBX_STYLE_FORM_NEW_GROUP)
);
$applicationComboBox = new CListBox('applications[]', $this->data['applications'], 6);
$applicationComboBox->addItem(0, '-'._('None').'-');
foreach ($this->data['db_applications'] as $application) {
$applicationComboBox->addItem($application['applicationid'], CHtml::encode($application['name']));
}
$itemFormList->addRow(_('Applications'), $applicationComboBox);
// Append application prototypes to form list.
$itemFormList->addRow(new CLabel(_('New application prototype'), 'new_application_prototype'),
(new CSpan(
(new CTextBox('new_application_prototype', $data['new_application_prototype']))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
))->addClass(ZBX_STYLE_FORM_NEW_GROUP)
);
$application_prototype_listbox = new CListBox('application_prototypes[]', $data['application_prototypes'], 6);
$application_prototype_listbox->addItem(0, '-'._('None').'-');
foreach ($data['db_application_prototypes'] as $application_prototype) {
$application_prototype_listbox->addItem($application_prototype['name'], $application_prototype['name']);
}
$itemFormList->addRow(_('Application prototypes'), $application_prototype_listbox);
// append description to form list
$itemFormList->addRow(_('Description'),
(new CTextArea('description', $this->data['description']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
);
// status
$enabledCheckBox = (new CCheckBox('status', ITEM_STATUS_ACTIVE))
->setChecked($this->data['status'] == ITEM_STATUS_ACTIVE);
$itemFormList->addRow(_('Create enabled'), $enabledCheckBox);
$preprocessing = (new CTable())
->setId('preprocessing')
->setHeader([
$readonly ? null : '',
new CColHeader(_('Name')),
new CColHeader(_('Parameters')),
new CColHeader(null),
$readonly ? null : (new CColHeader(_('Action')))->setWidth(50)
]);
foreach ($data['preprocessing'] as $i => $step) {
// Depeding on preprocessing type, display corresponding params field and placeholders.
$params = [];
// Use numeric box for multiplier, otherwise use text box.
if ($step['type'] == ZBX_PREPROC_MULTIPLIER) {
$params[] = (new CTextBox('preprocessing['.$i.'][params][0]',
array_key_exists('params', $step) ? $step['params'][0] : ''
))
->setAttribute('placeholder', _('number'))
->setReadonly($readonly);
}
else {
$params[] = (new CTextBox('preprocessing['.$i.'][params][0]',
array_key_exists('params', $step) ? $step['params'][0] : ''
))->setReadonly($readonly);
}
// Create a secondary param text box, so it can be hidden if necessary.
$params[] = (new CTextBox('preprocessing['.$i.'][params][1]',
(array_key_exists('params', $step) && array_key_exists(1, $step['params']))
? $step['params'][1]
: ''
))
->setAttribute('placeholder', _('output'))
->setReadonly($readonly);
// Add corresponding placeholders and show or hide text boxes.
switch ($step['type']) {
case ZBX_PREPROC_MULTIPLIER:
$params[1]->addStyle('display: none;');
break;
case ZBX_PREPROC_RTRIM:
case ZBX_PREPROC_LTRIM:
case ZBX_PREPROC_TRIM:
$params[0]->setAttribute('placeholder', _('list of characters'));
$params[1]->addStyle('display: none;');
break;
case ZBX_PREPROC_XPATH:
case ZBX_PREPROC_JSONPATH:
$params[0]->setAttribute('placeholder', _('path'));
$params[1]->addStyle('display: none;');
break;
case ZBX_PREPROC_REGSUB:
$params[0]->setAttribute('placeholder', _('pattern'));
break;
case ZBX_PREPROC_BOOL2DEC:
case ZBX_PREPROC_OCT2DEC:
case ZBX_PREPROC_HEX2DEC:
case ZBX_PREPROC_DELTA_VALUE:
case ZBX_PREPROC_DELTA_SPEED:
$params[0]->addStyle('display: none;');
$params[1]->addStyle('display: none;');
break;
}
if ($readonly) {
$itemForm->addVar('preprocessing['.$i.'][type]', $step['type']);
}
$preproc_types_cbbox = new CComboBox('preprocessing['.$i.'][type]', $step['type']);
foreach (get_preprocessing_types() as $group) {
$cb_group = new COptGroup($group['label']);
foreach ($group['types'] as $type => $label) {
$cb_group->addItem(new CComboItem($type, $label, ($type == $step['type'])));
}
$preproc_types_cbbox->addItem($cb_group);
}
$preprocessing->addRow(
(new CRow([
$readonly
? null
: (new CCol(
(new CDiv())->addClass(ZBX_STYLE_DRAG_ICON)
))->addClass(ZBX_STYLE_TD_DRAG_ICON),
$readonly
? (new CTextBox('preprocessing['.$i.'][type_name]', get_preprocessing_types($step['type'])))
->setReadonly(true)
: $preproc_types_cbbox,
$params[0],
$params[1],
$readonly
? null
: (new CButton('preprocessing['.$i.'][remove]', _('Remove')))
->addClass(ZBX_STYLE_BTN_LINK)
->addClass('element-table-remove')
]))->addClass('sortable')
);
}
$preprocessing->addRow(
(new CCol(
(new CButton('param_add', _('Add')))
->addClass(ZBX_STYLE_BTN_LINK)
->addClass('element-table-add')
->setEnabled(!$readonly)
))->setColSpan(5)
);
$item_preproc_list = (new CFormList('item_preproc_list'))
->addRow(_('Preprocessing steps'), $preprocessing);
// append tabs to form
$itemTab = (new CTabView())
->addTab('itemTab', $this->data['caption'], $itemFormList)
->addTab('preprocTab', _('Preprocessing'), $item_preproc_list);
if (!hasRequest('form_refresh')) {
$itemTab->setSelected(0);
}
// append buttons to form
if ($this->data['itemid'] != 0) {
$itemTab->setFooter(makeFormFooter(
new CSubmit('update', _('Update')), [
new CSubmit('clone', _('Clone')),
(new CButtonDelete(_('Delete item prototype?'),
url_params(['form', 'itemid', 'parent_discoveryid'])
))->setEnabled(!$readonly),
new CButtonCancel(url_params(['parent_discoveryid']))
]
));
}
else {
$itemTab->setFooter(makeFormFooter(
new CSubmit('add', _('Add')),
[new CButtonCancel(url_params(['parent_discoveryid']))]
));
}
$itemForm->addItem($itemTab);
$widget->addItem($itemForm);
require_once dirname(__FILE__).'/js/configuration.item.prototype.edit.js.php';
return $widget;
|