cancel
Showing results for 
Search instead for 
Did you mean: 
fwmonitor
Level 7

Examples of REST scripting

Jump to solution

Hello,

can somebody show some examples of using REST scripting, like add/delete list entries or modify rules?

best regards

0 Kudos
1 Solution

Accepted Solutions
asabban
Level 17

Re: Examples of REST scripting

Jump to solution

Hello,

the documentation is still being worked on, but it should be available soon.

To use REST there are come examples with CURL available which you can try on the command line.

1.) Write the REST URL into a variable (easier to read later):

export REST=http://localhost:4711/Konfigurator/REST

2.) You need to authenticate with valid credentials. MWG will return a Cookie which you need for further requests to be authenticated:

curl -i -c cookies.txt  -H "Authorization: Basic YWRtaW46d2ViZ2F0ZXdheQ==" -X POST "$REST/login"

curl -i -b cookies.txt "$REST/appliances"

3.) You can see all available lists by using

curl -i -b cookies.txt "$REST/list"

4.) You can create an empty list with

curl -i -b cookies.txt -X POST "$REST/list?name=newlist&type=category"

5.) Get a list

curl -i -b cookies.txt "$REST/list/com.scur.type.mediatype.4532"

6.) Get list entry

curl -i -b cookies.txt "$REST/list/com.scur.type.mediatype.4532/entry/1"

7.) Delete list entry

curl -i -b cookies.txt -X DELETE "$REST/list/com.scur.type.mediatype.4532/entry/1"

8.) Modify list entry

curl -i -b cookies.txt -X PUT -d @listEntryRequest.xml "$REST/list/com.scur.type.regex.11347/entry/1" -H "Content-Type: application/xml"

where "listEntryRequest.xml" is a file which contains the new entry, such as:

<entry xmlns="http://www.w3.org/2005/Atom">

<content type="application/xml">

<listEntry>

<entry>com.scur.category.192</entry>

  <description />

</listEntry>

</content>

</entry>

I hope this helps. Rule modification is not yet possible as far as I know. If you need specific examples, just let me know, I will try to provide them.

best,

Andre

0 Kudos
29 Replies
asabban
Level 17

Re: Examples of REST scripting

Jump to solution

Hello,

the documentation is still being worked on, but it should be available soon.

To use REST there are come examples with CURL available which you can try on the command line.

1.) Write the REST URL into a variable (easier to read later):

export REST=http://localhost:4711/Konfigurator/REST

2.) You need to authenticate with valid credentials. MWG will return a Cookie which you need for further requests to be authenticated:

curl -i -c cookies.txt  -H "Authorization: Basic YWRtaW46d2ViZ2F0ZXdheQ==" -X POST "$REST/login"

curl -i -b cookies.txt "$REST/appliances"

3.) You can see all available lists by using

curl -i -b cookies.txt "$REST/list"

4.) You can create an empty list with

curl -i -b cookies.txt -X POST "$REST/list?name=newlist&type=category"

5.) Get a list

curl -i -b cookies.txt "$REST/list/com.scur.type.mediatype.4532"

6.) Get list entry

curl -i -b cookies.txt "$REST/list/com.scur.type.mediatype.4532/entry/1"

7.) Delete list entry

curl -i -b cookies.txt -X DELETE "$REST/list/com.scur.type.mediatype.4532/entry/1"

8.) Modify list entry

curl -i -b cookies.txt -X PUT -d @listEntryRequest.xml "$REST/list/com.scur.type.regex.11347/entry/1" -H "Content-Type: application/xml"

where "listEntryRequest.xml" is a file which contains the new entry, such as:

<entry xmlns="http://www.w3.org/2005/Atom">

<content type="application/xml">

<listEntry>

<entry>com.scur.category.192</entry>

  <description />

</listEntry>

</content>

</entry>

I hope this helps. Rule modification is not yet possible as far as I know. If you need specific examples, just let me know, I will try to provide them.

best,

Andre

0 Kudos
fwmonitor
Level 7

Re: Examples of REST scripting

Jump to solution

Hello,

is it possible on this way to modify permissions for ruleset?

regards

0 Kudos
eelsasser
Level 15

Re: Examples of REST scripting

Jump to solution

The current implementation of of REST on MWG only allows you to do certain functions.

Actions:

restart

shutdown

flushcache

rotateLogs

rotateAndPushLogs

license

Logs and file server files:

list of directories and log files

download log file

delete log file

list of files

download file

add file

modify file

delete file

And manipulate lists. Add/Remove/Modify/etc.

It does not provide access tot he rules or policy, other than the list contents.

0 Kudos
fwmonitor
Level 7

Re: Examples of REST scripting

Jump to solution

Hello,

the retrieving and uploading of lists works on MWG 7.1.6, but if trying to delete an entry I get a parser output "org.apache.abdera.parser.stax.FOMEntry...".

the beta 7.2.0 shows no error message but the entry still present, cannot be deleted.

can you check this issue? Is it a bug or the "delete" requieres an another syntax?

regards

0 Kudos
dstraube
Level 11

Re: Examples of REST scripting

Jump to solution

Hello,

to delete a list you just need to issue a DELETE request using the list-ID. Following the examples posted earlier it should look like this:

curl -i -b cookies.txt -X DELETE "$REST/list/com.scur.type.regex.4537"

Can you give an example of the request you are sending? So far I haven't seen the error you mentioned.

Regards,

Dirk

0 Kudos
fwmonitor
Level 7

Re: Examples of REST scripting

Jump to solution

Hello, the output attached

0 Kudos
dstraube
Level 11

Re: Examples of REST scripting

Jump to solution

Yes, that's a bug. The command is correct and should work. I can reproduce the error with MWG 7.1.6.1.

I can't reproduce it with MWG 7.2 (which will be released fairly soon), so it seems that it's fixed. Deleting entries or the whole list worked fine in my test and after a commit the changed entries or the list was actually gone. I tested with the latest internal MWG 7.2 build, I haven't checked with the Beta build yet.

If you need the fix to be backported to the 7.1.6 branch, please raise a ticket with support.

Regards,

Dirk

0 Kudos
consoul
Level 9

Re: Examples of REST scripting

Jump to solution

How do you log back out? In testing I end up with many many active sessions, which creates problems if you dont allow multiple logins per account. Thoughts?

0 Kudos
eelsasser
Level 15

Re: Examples of REST scripting

Jump to solution

If you are using the examples set forth in the docs with curl:

curl -i -b cookies.txt -X POST "$REST/logout"

Message was edited by: eelsasser on 6/18/13 3:12:22 PM EDT
0 Kudos