Reply
Highlighted
Accepted Solution

Can I use RegEx with fileop via WAPI

bradm
Techie
Posts: 4
5838     0

Is it possible to filter the data going into a csv created by fileop using RegEx in the json body, or some similar way? I would like to generate a csv that contains all hosts with a name ~= .*-sm-.*

 

I am looking for all hosts with the "-sm-" string in the name. I can use ".*-sm-*" in the Advanced global search in the GUI. I want to export a csv with these hosts. I can export a csv for all hosts using the following:

 

POST https://1.1.1.1/wapi/v2.2/fileop?_function=csv_export

With json body:

{"_object": "record:host"}

 

Or Refine it using json body:

{"_object": "record:host",
"zone" : "domain.net",
"name" : "this-sm-12345.domain.net"
}

 

But if I try passing a regular expression in the "name" value in the body, it seems to take it literaly, as you might expect since it is in quotes. Is there a way for me to accomplish filtering using fileop without an exact match to a value? i.e. (using wildcards in a regex)

 

{"_object": "record:host",
"zone" : "domain.net",
"name" : ".*-sm-.*"

 

For which I currently get the following error, even though the previous example with "name" : "this-sm-12345.domain.net" returns a hostaddress and hostrecord.

 

{
"Error": "AdmConDataNotFoundError: The CSV search did not match any objects",
"code": "Client.Ibap.Data.NotFound",
"text": "The CSV search did not match any objects"
}

 

Is there a better way to generate a csv export of all hosts filtered in a similar fashion? Thank you for any help. 

Re: Can I use RegEx with fileop via WAPI

Adviser
Posts: 43
5839     0

Try

 

{"_object": "record:host",
"zone" : "domain.net",
"name~" : ".*-sm-.*"

 

 

Re: Can I use RegEx with fileop via WAPI

bradm
Techie
Posts: 4
5839     0

That worked perfectly. 

 

Thank you JVoss!

Showing results for 
Search instead for 
Do you mean 

Recommended for You