Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Automate your automation with Rudder’s API! \o/


Published on

Rudder comes with a complete REST API which provides access to all data available within Rudder so you can automate your configuration automation without using the web interface.

Using it, you can create tools (scripts, UI) adapted to your environment to automate common tasks in Rudder (Change a single setting in a Directive? Enable or disable a Rule according on customer request? Accept new nodes via a third party interface) or integrate existing tools like your CMDB, monitoring or even a KPI-reporting system.

We try to provide lot of documentation and make it as user friendly as possible, but it’s not always easy to realise exactly what the API can do, or figure out to best use it.

In this hands-on session, I will first explain how Rudder API works and is organized. Then, we will practice our knowledge (and our Python) to create a tool over Rudder API.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Automate your automation with Rudder’s API! \o/

  1. 1. RUDDER REST API LET'S AUTOMATE YOUR AUTOMATION O/ Vincent Membré - Configuration Management Camp 2017
  2. 2. WHOAMI Developper @ Normation on Rudder. Mostly works on Scala parts ( backend / API ) But also lot of Javascript and python I love to automate things (I'm lazy) 1,66 daughters (and not much sleep)
  3. 3. General presentation of Rudder API How to use it Demo questions / what do you want to build ?
  4. 4. RUDDER REST API Added in Rudder 2.7. Grew up over time, you can now manage almost everything in Rudder (ie: miss authorized networks :( ) A legacy API is still existing from the old days, but only localhost Online documentation: http://www.rudder-
  5. 5. EXAMPLE WITH CURL Base url: https//your.server.rudder/rudder/api curl -k https//your.server.rudder/rudder/api
  6. 6. AUTHENTICATION Authenticate using tokens. Created in API accounts page Pass them as Headers Give access to the whole api
  7. 7. EXAMPLE WITH CURL curl -k https//your.server.rudder/rudder/api -H "X-Api-Token: yourToken"
  8. 8. VERSIONNING POLICY A new version when we change behavior ( response, parameters) We can add new endpoints in an existing version ( techniques api) In practice a new version by new version of Rudder (9 for now) Use 'latest' version for 'latest' available
  9. 9. SELECTING VERSION Use a Header curl -k https//your.server.rudder/rudder/api -H "X-Api-Token: yourToken" -H "X-Api-Version: latest"
  10. 10. SELECTING VERSION Put in Url curl -k https//your.server.rudder/rudder/api/latest -H "X-Api-Token: yourToken"
  11. 11. ENDPOINTS One endpoint for each element in Rudder Rules,Directives, Groups, Nodes, Compliance Parameters, Settings, Techniques, Change requests curl -k https//your.server.rudder/rudder/api/latest/nodes -H "X-Api-Token: yourToken"
  12. 12. METHODS HTTP method map to action type Get Put (Create) Post (Modification / action) Delete curl -k https//your.server.rudder/rudder/api/latest/nodes -X GET -H "X-Api-Token: yourToken"
  13. 13. PASSING PARAMETERS Url parameters form data Json
  14. 14. URL PARAMETERS Part of the url Mostly Ids of the element to access curl https//your.server.rudder/rudder/api/latest/nodes/nodeId -X GET -H "X-Api-Token: yourToken" -k
  15. 15. FORM DATA Key=value Either in Url or form data Great for small amount of data, simple and manual requests curl https//your.server.rudder/rudder/api/latest/nodes/nodeId?include=ip -H "X-Api-Token: yourToken" -k
  16. 16. JSON Passing a json in request body Need to add Header "Content-type: application/json" Great when passing lots of parameters, complex and automated requests curl -k https//your.server.rudder/rudder/api/latest/nodes/nodeId -X POST -d @json -H "Content-type: application/json" -H "X-Api-Token
  17. 17. JSON CONTENT { "policy" : "audit" , "properties" : [ { "name": "env_type" , "value": "production" } , { "name": "shell" , "value": "/bin/sh" } , { "name": "utf-8 poetry", "value": "ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ ] }
  18. 18. RESPONSE FORMAT { "action": The name of the called function, "id": The ID of the element you want, if relevant, "result": The result of your action: success or error, "data": Only present if this is a success and depends on the funct "errorDetails": Only present if this is an error, it contains }
  19. 19. DEMO GO TO DEMO
  21. 21. THE END