/** * Fetch this object's obfuscated custom variables * * @return $this */ public function fetchCustomvars() { if ($this->backend->is('livestatus')) { $this->customvars = array(); return $this; } $blacklist = array(); $blacklistPattern = ''; if (($blacklistConfig = Config::module('monitoring')->get('security', 'protected_customvars', '')) !== '') { foreach (explode(',', $blacklistConfig) as $customvar) { $nonWildcards = array(); foreach (explode('*', $customvar) as $nonWildcard) { $nonWildcards[] = preg_quote($nonWildcard, '/'); } $blacklist[] = implode('.*', $nonWildcards); } $blacklistPattern = '/^(' . implode('|', $blacklist) . ')$/i'; } if ($this->type === self::TYPE_SERVICE) { $this->fetchServiceVariables(); $customvars = $this->serviceVariables; } else { $this->fetchHostVariables(); $customvars = $this->hostVariables; } $this->customvars = $customvars; $this->hideBlacklistedProperties(); if ($blacklistPattern) { $this->customvars = $this->obfuscateCustomVars($this->customvars, $blacklistPattern); } return $this; }
/** * Fetch this object's obfuscated custom variables * * @return $this */ public function fetchCustomvars() { if ($this->backend->is('livestatus')) { $this->customvars = array(); return $this; } $blacklist = array(); $blacklistPattern = '/^(.*pw.*|.*pass.*|community)$/i'; if (($blacklistConfig = Config::module('monitoring')->get('security', 'protected_customvars', '')) !== '') { foreach (explode(',', $blacklistConfig) as $customvar) { $nonWildcards = array(); foreach (explode('*', $customvar) as $nonWildcard) { $nonWildcards[] = preg_quote($nonWildcard, '/'); } $blacklist[] = implode('.*', $nonWildcards); } $blacklistPattern = '/^(' . implode('|', $blacklist) . ')$/i'; } if ($this->type === self::TYPE_SERVICE) { $this->fetchServiceVariables(); $customvars = $this->serviceVariables; } else { $this->fetchHostVariables(); $customvars = $this->hostVariables; } $this->customvars = array(); foreach ($customvars as $name => $value) { if ($blacklistPattern && preg_match($blacklistPattern, $name)) { $this->customvars[$name] = '***'; } else { $this->customvars[$name] = $value; } } return $this; }
/** * Fetch the object's contact groups * * @return $this */ public function fetchContactgroups() { if ($this->backend->is('livestatus')) { $this->contactgroups = array(); return $this; } $contactsGroups = $this->backend->select()->from('contactgroup', array('contactgroup_name', 'contactgroup_alias')); if ($this->type === self::TYPE_SERVICE) { $contactsGroups->where('service_host_name', $this->host_name)->where('service_description', $this->service_description); } else { $contactsGroups->where('host_name', $this->host_name); } $this->contactgroups = $contactsGroups->applyFilter($this->getFilter())->getQuery()->fetchAll(); return $this; }
/** * Fetch the object's custom variables * * @return $this */ public function fetchCustomvars() { if ($this->backend->is('livestatus')) { $this->customvars = array(); return $this; } $blacklist = array(); $blacklistPattern = '/^(.*pw.*|.*pass.*|community)$/i'; if (($blacklistConfig = Config::module('monitoring')->get('security', 'protected_customvars', '')) !== '') { foreach (explode(',', $blacklistConfig) as $customvar) { $nonWildcards = array(); foreach (explode('*', $customvar) as $nonWildcard) { $nonWildcards[] = preg_quote($nonWildcard, '/'); } $blacklist[] = implode('.*', $nonWildcards); } $blacklistPattern = '/^(' . implode('|', $blacklist) . ')$/i'; } $query = $this->backend->select()->from('customvar', array('varname', 'varvalue', 'is_json'))->where('object_type', $this->type)->where('host_name', $this->host_name); if ($this->type === self::TYPE_SERVICE) { $query->where('service_description', $this->service_description); } $this->customvars = array(); $customvars = $query->getQuery()->fetchAll(); foreach ($customvars as $cv) { $name = strtolower($cv->varname); if ($blacklistPattern && preg_match($blacklistPattern, $cv->varname)) { $this->customvars[$name] = '***'; } elseif ($cv->is_json) { $this->customvars[$name] = json_decode($cv->varvalue); } else { $this->customvars[$name] = $cv->varvalue; } } return $this; }