diff --git a/library/Netboximport/ProvidedHook/Director/ImportSource.php b/library/Netboximport/ProvidedHook/Director/ImportSource.php index feaef2a..94ec80d 100644 --- a/library/Netboximport/ProvidedHook/Director/ImportSource.php +++ b/library/Netboximport/ProvidedHook/Director/ImportSource.php @@ -36,7 +36,7 @@ function flattenArray($prefix, $array, $autoflatten_elements = array(), $flatten } private function fetchObjects($ressource, $activeOnly, $autoflatten_elements, $additionalKeysCallback = null) { - $objects = $this->api->get($ressource); + $objects = $this->api->get($ressource,$this->getFilters()); //Filter only active objects if setting is set $objects = array_filter($objects, function ($object) use ($activeOnly) { @@ -201,6 +201,11 @@ public static function addSettingsFormFields(QuickForm $form) { $form->addElement('YesNo', 'importvirtualmachines', array( 'label' => $form->translate('Import virtual machines'), 'description' => $form->translate('Import virtual machines (virtualization/virtual-machines in netbox).'), + )); + + $form->addElement('text', 'filters', array( + 'label' => $form->translate("Filterstring"), + 'description' => $form->translate("Filters to be applied in API request (e.g. role=Server"), )); $form->addElement('YesNo', 'activeonly', array( @@ -257,6 +262,11 @@ public function fetchData() { } + private function getFilters() { + parse_str($this->getSetting('filters'),$filters_array); + return $filters_array; + } + public function listColumns() { // return a list of all keys, which appeared in any of the objects return array_keys(array_merge(...array_map('get_object_vars', $this->fetchData())));