1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22/** 23 * @var CView $this 24 */ 25?> 26 27<script type="text/x-jquery-tmpl" id="delayFlexRow"> 28 <tr class="form_row"> 29 <td> 30 <ul class="<?= CRadioButtonList::ZBX_STYLE_CLASS ?>" id="delay_flex_#{rowNum}_type"> 31 <li> 32 <input type="radio" id="delay_flex_#{rowNum}_type_0" name="delay_flex[#{rowNum}][type]" value="0" checked="checked"> 33 <label for="delay_flex_#{rowNum}_type_0"><?= _('Flexible') ?></label> 34 </li><li> 35 <input type="radio" id="delay_flex_#{rowNum}_type_1" name="delay_flex[#{rowNum}][type]" value="1"> 36 <label for="delay_flex_#{rowNum}_type_1"><?= _('Scheduling') ?></label> 37 </li> 38 </ul> 39 </td> 40 <td> 41 <input type="text" id="delay_flex_#{rowNum}_delay" name="delay_flex[#{rowNum}][delay]" maxlength="255" placeholder="<?= ZBX_ITEM_FLEXIBLE_DELAY_DEFAULT ?>"> 42 <input type="text" id="delay_flex_#{rowNum}_schedule" name="delay_flex[#{rowNum}][schedule]" maxlength="255" placeholder="<?= ZBX_ITEM_SCHEDULING_DEFAULT ?>" style="display: none;"> 43 </td> 44 <td> 45 <input type="text" id="delay_flex_#{rowNum}_period" name="delay_flex[#{rowNum}][period]" maxlength="255" placeholder="<?= ZBX_DEFAULT_INTERVAL ?>"> 46 </td> 47 <td> 48 <button type="button" id="delay_flex_#{rowNum}_remove" name="delay_flex[#{rowNum}][remove]" class="<?= ZBX_STYLE_BTN_LINK ?> element-table-remove"><?= _('Remove') ?></button> 49 </td> 50 </tr> 51</script> 52<script type="text/javascript"> 53 jQuery(function($) { 54 $('#delayFlexTable').on('click', 'input[type="radio"]', function() { 55 var rowNum = $(this).attr('id').split('_')[2]; 56 57 if ($(this).val() == <?= ITEM_DELAY_FLEXIBLE; ?>) { 58 $('#delay_flex_' + rowNum + '_schedule').hide(); 59 $('#delay_flex_' + rowNum + '_delay').show(); 60 $('#delay_flex_' + rowNum + '_period').show(); 61 } 62 else { 63 $('#delay_flex_' + rowNum + '_delay').hide(); 64 $('#delay_flex_' + rowNum + '_period').hide(); 65 $('#delay_flex_' + rowNum + '_schedule').show(); 66 } 67 }); 68 69 $('#delayFlexTable').dynamicRows({ 70 template: '#delayFlexRow' 71 }); 72 }); 73</script> 74<?php 75 76/* 77 * Visibility 78 */ 79$this->data['typeVisibility'] = []; 80 81if ($data['display_interfaces']) { 82 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_ZABBIX, 'interface_row'); 83 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_ZABBIX, 'interfaceid'); 84 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SIMPLE, 'interface_row'); 85 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SIMPLE, 'interfaceid'); 86 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SNMP, 'interface_row'); 87 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SNMP, 'interfaceid'); 88 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_EXTERNAL, 'interface_row'); 89 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_EXTERNAL, 'interfaceid'); 90 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_IPMI, 'interface_row'); 91 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_IPMI, 'interfaceid'); 92 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SSH, 'interface_row'); 93 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SSH, 'interfaceid'); 94 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_TELNET, 'interface_row'); 95 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_TELNET, 'interfaceid'); 96 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_JMX, 'interface_row'); 97 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_JMX, 'interfaceid'); 98 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SNMPTRAP, 'interface_row'); 99 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SNMPTRAP, 'interfaceid'); 100 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_HTTPAGENT, 'interface_row'); 101 zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_HTTPAGENT, 'interfaceid'); 102} 103zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SIMPLE, 'row_username'); 104zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SIMPLE, 'username'); 105zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SIMPLE, 'row_password'); 106zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SIMPLE, 'password'); 107zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SNMP, 'snmp_oid'); 108zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SNMP, 'row_snmp_oid'); 109zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_IPMI, 'ipmi_sensor'); 110zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_IPMI, 'row_ipmi_sensor'); 111zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SSH, 'authtype'); 112zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SSH, 'row_authtype'); 113zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SSH, 'username'); 114zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SSH, 'row_username'); 115zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_TELNET, 'username'); 116zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_TELNET, 'row_username'); 117zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_DB_MONITOR, 'username'); 118zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_DB_MONITOR, 'row_username'); 119zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_JMX, 'username'); 120zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_JMX, 'row_username'); 121zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_JMX, 'jmx_endpoint'); 122zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_JMX, 'row_jmx_endpoint'); 123zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SSH, 'password'); 124zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SSH, 'row_password'); 125zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_TELNET, 'password'); 126zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_TELNET, 'row_password'); 127zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_DB_MONITOR, 'password'); 128zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_DB_MONITOR, 'row_password'); 129zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_JMX, 'password'); 130zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_JMX, 'row_password'); 131zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SSH, 'label_executed_script'); 132zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_TELNET, 'label_executed_script'); 133zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_DB_MONITOR, 'label_params'); 134zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_CALCULATED, 'label_formula'); 135zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SSH, 'params_script'); 136zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_SSH, 'row_params'); 137zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_TELNET, 'params_script'); 138zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_TELNET, 'row_params'); 139zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_DB_MONITOR, 'params_dbmonitor'); 140zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_DB_MONITOR, 'row_params'); 141zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_CALCULATED, 'params_calculted'); 142zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_CALCULATED, 'row_params'); 143zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_TRAPPER, 'trapper_hosts'); 144zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_TRAPPER, 'row_trapper_hosts'); 145zbx_subarray_push($this->data['typeVisibility'], ITEM_TYPE_DEPENDENT, 'row_master_item'); 146$ui_rows = [ 147 ITEM_TYPE_HTTPAGENT => [ 148 'url_row', 'query_fields_row', 'request_method_row', 'timeout_row', 'post_type_row', 'posts_row', 'headers_row', 149 'status_codes_row', 'follow_redirects_row', 'retrieve_mode_row', 'output_format_row', 'allow_traps_row', 150 'request_method', 'http_proxy_row', 'http_authtype_row', 'http_authtype', 'verify_peer_row', 'verify_host_row', 151 'ssl_key_file_row', 'ssl_cert_file_row', 'ssl_key_password_row', 'trapper_hosts', 'allow_traps' 152 ], 153 ITEM_TYPE_SCRIPT => [ 154 'parameters_row', 'script_row', 'timeout_row' 155 ] 156]; 157foreach ($ui_rows as $type => $rows) { 158 foreach ($rows as $row) { 159 zbx_subarray_push($this->data['typeVisibility'], $type, $row); 160 } 161} 162 163foreach ($this->data['types'] as $type => $label) { 164 switch ($type) { 165 case ITEM_TYPE_DB_MONITOR: 166 $defaultKey = $this->data['is_discovery_rule'] 167 ? ZBX_DEFAULT_KEY_DB_MONITOR_DISCOVERY 168 : ZBX_DEFAULT_KEY_DB_MONITOR; 169 zbx_subarray_push($this->data['typeVisibility'], $type, 170 ['id' => 'key', 'defaultValue' => $defaultKey] 171 ); 172 break; 173 case ITEM_TYPE_SSH: 174 zbx_subarray_push($this->data['typeVisibility'], $type, 175 ['id' => 'key', 'defaultValue' => ZBX_DEFAULT_KEY_SSH] 176 ); 177 break; 178 case ITEM_TYPE_TELNET: 179 zbx_subarray_push($this->data['typeVisibility'], $type, 180 ['id' => 'key', 'defaultValue' => ZBX_DEFAULT_KEY_TELNET] 181 ); 182 break; 183 default: 184 zbx_subarray_push($this->data['typeVisibility'], $type, ['id' => 'key', 'defaultValue' => '']); 185 } 186} 187foreach ($this->data['types'] as $type => $label) { 188 if ($type == ITEM_TYPE_TRAPPER || $type == ITEM_TYPE_SNMPTRAP || $type == ITEM_TYPE_DEPENDENT) { 189 continue; 190 } 191 192 zbx_subarray_push($this->data['typeVisibility'], $type, 'row_flex_intervals'); 193} 194foreach ($this->data['types'] as $type => $label) { 195 if ($type == ITEM_TYPE_TRAPPER || $type == ITEM_TYPE_SNMPTRAP || $type == ITEM_TYPE_DEPENDENT) { 196 continue; 197 } 198 zbx_subarray_push($this->data['typeVisibility'], $type, 'delay'); 199 zbx_subarray_push($this->data['typeVisibility'], $type, 'row_delay'); 200} 201 202$this->data['authTypeVisibility'] = []; 203zbx_subarray_push($this->data['authTypeVisibility'], ITEM_AUTHTYPE_PUBLICKEY, 'publickey'); 204zbx_subarray_push($this->data['authTypeVisibility'], ITEM_AUTHTYPE_PUBLICKEY, 'row_publickey'); 205zbx_subarray_push($this->data['authTypeVisibility'], ITEM_AUTHTYPE_PUBLICKEY, 'privatekey'); 206zbx_subarray_push($this->data['authTypeVisibility'], ITEM_AUTHTYPE_PUBLICKEY, 'row_privatekey'); 207zbx_subarray_push($this->data['typeDisable'], ITEM_TYPE_CALCULATED, [ITEM_VALUE_TYPE_STR, ITEM_VALUE_TYPE_LOG, ITEM_VALUE_TYPE_TEXT], 'value_type'); 208 209?> 210<script type="text/javascript"> 211 function setAuthTypeLabel() { 212 if (jQuery('#authtype').val() == <?= json_encode(ITEM_AUTHTYPE_PUBLICKEY) ?> 213 && jQuery('#type').val() == <?= json_encode(ITEM_TYPE_SSH) ?>) { 214 jQuery('#row_password label').html(<?= json_encode(_('Key passphrase')) ?>); 215 } 216 else { 217 jQuery('#row_password label').html(<?= json_encode(_('Password')) ?>); 218 } 219 } 220 221 function updateItemFormElements() { 222 // test button 223 var testable_item_types = <?= json_encode(CControllerPopupItemTest::getTestableItemTypes($this->data['hostid'])) ?>, 224 type = parseInt(jQuery('#type').val()), 225 key = jQuery('#key').val(); 226 227 if (type == <?= ITEM_TYPE_SIMPLE ?> && (key.substr(0, 7) === 'vmware.' || key.substr(0, 8) === 'icmpping')) { 228 jQuery('#test_item').prop('disabled', true); 229 } 230 else { 231 jQuery('#test_item').prop('disabled', (testable_item_types.indexOf(type) == -1)); 232 } 233 234 // delay field 235 if (type == <?= ITEM_TYPE_ZABBIX_ACTIVE ?>) { 236 if (key.substr(0, 8) === 'mqtt.get') { 237 globalAllObjForViewSwitcher['type'].hideObj(<?= json_encode(['id' => 'delay']) ?>); 238 globalAllObjForViewSwitcher['type'].hideObj(<?= json_encode(['id' => 'row_delay']) ?>); 239 globalAllObjForViewSwitcher['type'].hideObj(<?= json_encode(['id' => 'row_flex_intervals']) ?>); 240 } 241 else { 242 globalAllObjForViewSwitcher['type'].showObj(<?= json_encode(['id' => 'delay']) ?>); 243 globalAllObjForViewSwitcher['type'].showObj(<?= json_encode(['id' => 'row_delay']) ?>); 244 globalAllObjForViewSwitcher['type'].showObj(<?= json_encode(['id' => 'row_flex_intervals']) ?>); 245 } 246 } 247 } 248 249 jQuery(document).ready(function($) { 250 <?php 251 if (!empty($this->data['authTypeVisibility'])) { ?> 252 var authTypeSwitcher = new CViewSwitcher('authtype', 'change', 253 <?php echo zbx_jsvalue($this->data['authTypeVisibility'], true); ?>); 254 <?php } 255 if (!empty($this->data['typeVisibility'])) { ?> 256 var typeSwitcher = new CViewSwitcher('type', 'change', 257 <?php echo zbx_jsvalue($this->data['typeVisibility'], true); ?>, 258 <?php echo zbx_jsvalue($this->data['typeDisable'], true); ?>); 259 <?php } ?> 260 if ($('#http_authtype').length) { 261 new CViewSwitcher('http_authtype', 'change', <?= zbx_jsvalue([ 262 HTTPTEST_AUTH_BASIC => ['http_username_row', 'http_password_row'], 263 HTTPTEST_AUTH_NTLM => ['http_username_row', 'http_password_row'], 264 HTTPTEST_AUTH_KERBEROS => ['http_username_row', 'http_password_row'], 265 HTTPTEST_AUTH_DIGEST => ['http_username_row', 'http_password_row'] 266 ], true) ?>); 267 } 268 269 if ($('#allow_traps').length) { 270 new CViewSwitcher('allow_traps', 'change', <?= zbx_jsvalue([ 271 HTTPCHECK_ALLOW_TRAPS_ON => ['row_trapper_hosts'] 272 ], true) ?>); 273 } 274 275 $("#key").on('keyup change', updateItemFormElements); 276 277 $('#parameters_table').dynamicRows({template: '#parameters_table_row'}); 278 279 $('#type') 280 .change(function() { 281 var item_interface_types = <?= json_encode(itemTypeInterface()) ?>, 282 interface_ids_by_types = <?= json_encode($interface_ids_by_types) ?>; 283 284 updateItemFormElements(); 285 organizeInterfaces(interface_ids_by_types, item_interface_types, parseInt($(this).val())); 286 287 setAuthTypeLabel(); 288 }) 289 .trigger('change'); 290 291 $('#test_item').on('click', function() { 292 var step_nums = []; 293 $('z-select[name^="preprocessing"][name$="[type]"]', $('#preprocessing')).each(function() { 294 var str = $(this).attr('name'); 295 step_nums.push(str.substr(14, str.length - 21)); 296 }); 297 298 openItemTestDialog(step_nums, true, true, this, -2); 299 }); 300 301 $('#authtype').bind('change', function() { 302 setAuthTypeLabel(); 303 }); 304 305 $('[data-action="parse_url"]').click(function(e) { 306 var url_node = $(this).siblings('[name="url"]'), 307 table = $('#query_fields_pairs').data('editableTable'), 308 url = parseUrlString(url_node.val()) 309 310 if (typeof url === 'object') { 311 if (url.pairs.length > 0) { 312 table.addRows(url.pairs); 313 table.getTableRows().map(function() { 314 var empty = $(this).find('input[type="text"]').map(function() { 315 return $(this).val() == '' ? this : null; 316 }); 317 318 return empty.length == 2 ? this : null; 319 }).map(function() { 320 table.removeRow(this); 321 }); 322 } 323 324 url_node.val(url.url); 325 } 326 else { 327 overlayDialogue({ 328 'title': <?= json_encode(_('Error')); ?>, 329 'content': $('<span>').html(<?= 330 json_encode(_('Failed to parse URL.').'<br><br>'._('URL is not properly encoded.')); 331 ?>), 332 'buttons': [ 333 { 334 title: <?= json_encode(_('Ok')); ?>, 335 class: 'btn-alt', 336 focused: true, 337 action: function() {} 338 } 339 ] 340 }, e.target); 341 } 342 }); 343 344 $('#request_method').change(function() { 345 if ($(this).val() == <?= HTTPCHECK_REQUEST_HEAD ?>) { 346 $(':radio', '#retrieve_mode') 347 .filter('[value=<?= HTTPTEST_STEP_RETRIEVE_MODE_HEADERS ?>]').click() 348 .end() 349 .prop('disabled', true); 350 } 351 else { 352 $(':radio', '#retrieve_mode').prop('disabled', false); 353 } 354 }); 355 }); 356</script> 357