From 273478094ca50db0f4f2da8132d9df755f12d9ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Jonak-M=C3=B6chel?= Date: Mon, 19 Oct 2020 12:15:51 +0200 Subject: [PATCH] feature: add possibility to add filter string fixes #15 --- .../ProvidedHook/Director/ImportSource.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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())));