Guest User

Untitled

a guest
Nov 27th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. Shell :
  2.  
  3. curl --digest 'http://monitor:monitor-123@localhost:9990/management' --header "Content-Type: application/json" -d '{"operation":"read-attribute","name":"server-state","json.pretty":1}'
  4.  
  5. Ruby :
  6.  
  7. #!/usr/bin/ruby
  8. require 'rubygems'
  9. require 'net/http'
  10. require 'json'
  11. require 'uri'
  12. require 'net/http/digest_auth'
  13.  
  14. digest_auth = Net::HTTP::DigestAuth.new
  15.  
  16. url = URI.parse("http://localhost:9990/management")
  17. url.user = 'monitor'
  18. url.password = 'monitor-123'
  19.  
  20. payload = { "operation" => "read-attribute", "name" => "server-state", "json.pretty" => 1 }
  21. pj=payload.to_json
  22.  
  23. http = Net::HTTP.new(url.host, url.port)
  24.  
  25. request = Net::HTTP::Get.new url.path
  26.  
  27. response = http.request request
  28. # response is a 401 response with a WWW-Authenticate header
  29.  
  30. auth = digest_auth.auth_header url, response['www-authenticate'], 'POST'
  31.  
  32. # create a new request with the Authorization header
  33. request = Net::HTTP::Post.new(url.path, initheader = {'Content-Type' =>'application/json'})
  34. request.add_field 'Authorization', auth
  35.  
  36. # re-issue request with Authorization
  37. request.body = pj
  38. response=http.request(request)
  39. puts response
Advertisement
Add Comment
Please, Sign In to add comment