RESTful management services consist of two sets of resources. tenant-monitoring resources and 'wls' resources. The first is more flexible in response format (JSON, XML, HTML) and more suitable for monitoring. With the latter you can for example update datasource properties and create entire servers. It however only supports JSON as return format. The 'wls' resources also provide links so you can automagically traverse the resource tree which is very useful. I've provided a Python script to do just that at the end of this post.
Monitoring
In the past I have already created all kinds of tools to do remote monitoring of WebLogic Server 11g. See for example http://javaoraclesoa.blogspot.nl/2012/09/monitoring-datasources-on-weblogic.html for some code to monitor datasources and for the state of the SOA Infrastructure; http://javaoraclesoa.blogspot.nl/2012/11/soa-suite-cluster-deployments-and.html and also for BPEL: http://javaoraclesoa.blogspot.nl/2013/03/monitoring-oracle-soa-suite-11g.html.
With the 12c RESTful Management Services this becomes a lot easier and does not require any custom code, which is of course a major improvement!
It is possible to let the RESTful Management Services return HTML, JSON or XML by using the Accept HTTP header (application/json or application/xml. HTML is the default). See here.
What can you monitor?
Available resources under http(s)://host:port/management/tenant-monitoring are (WLS 12.1.1):
- servers
- clusters
- applications
- datasources
You can also go to the level of an individual resource like for example datasources/datasourcename.
SOA Suite
The tenant-monitoring resources of the RESTful Management Services are not specific for SOA Suite. They do not allow you to obtain much information about the inner workings of applications like the SOA infrastructure application or the BPEL process manager. Thus my SOA infrastructure monitoring tool and BPEL process state monitoring tool could still be useful. You can potentially replace this functionality however with for example Jolokia. See below.
Monitoring a lot of resources
Because the Management Services allow monitoring of many resources, they would be ideal to use in a monitoring tool like Nagios. Mark Otting beat me to this however; http://www.qualogy.com/monitoring-weblogic-12c-with-nagios-and-rest/.
The RESTful Management services provide a specific set of resources which you can monitor. These resources are limited. There is also an alternative for the RESTful Management Services for monitoring WebLogic Server (and other application servers), namely Jolokia. See here. One of the nice things about Jolokia is that it allows you to directly access MBeans and you are not limited to a fixed set of available resources. Directly accessing MBeans is very powerful (and potentially dangerous!). This could for example allow obtaining SOA infrastructure state and list deployed composites.
Management
The RESTful Management Services do not only provide monitoring capabilities but also editable resources;
http://docs.oracle.com/middleware/1213/wls/WLRMR/resources.htm#WLRMR471. These resources can be accessed by going to an URL like; http(s)://host:port/management/wls/{version}/path, for example http://localhost:7001/management/wls/latest/. The resources only provide the option to reply with JSON (Accept: application/json) and provide links entries so you can see the parent and children of a resource. With POST, PUT and DELETE HTTP verbs you can update, create or remove resources and with GET and OPTIONS you can obtain information.
Deploying without dependencies (just curl)
An interesting usecase is command-line deployments without dependencies. This was an example given in the Oracle documentation. (see here). You could use for example a curl command (or whatever command-line HTTP client) to deploy an ear without need for Java libraries or WLST/Ant/Maven scripts.
Walking the resource tree
In contrast to the tenant-monitoring resources, the management resources allow traversing the JSON tree. The response of a HTTP GET request contains a links element, which contains parent and child entries. When an HTTP GET is not allowed or the links element does not exist, you can't go any further down the resource. In order to display available resources on your WebLogic Server I wrote a small Python script.
import json
import httplib
import base64
import string
from urlparse import urlparse
WLS_HOST = "localhost"
WLS_PORT = "7101"
WLS_USERNAME = "weblogic"
WLS_PASSWORD = "Welcome01"
def do_http_request(host,port,url,verb,accept,username,password,body):
# from http://mozgovipc.blogspot.nl/2012/06/python-http-basic-authentication-with.html
# base64 encode the username and password
auth = string.strip(base64.encodestring(username + ':' + password))
service = httplib.HTTP(host,port)
# write your headers
service.putrequest(verb, url)
service.putheader("Host", host)
service.putheader("User-Agent", "Python http auth")
service.putheader("Content-type", "text/html; charset=\"UTF-8\"")
# write the Authorization header like: 'Basic base64encode(username + ':' + password)
service.putheader("Authorization", "Basic %s" % auth)
service.putheader("Accept",accept)
service.endheaders()
service.send(body)
# get the response
statuscode, statusmessage, header = service.getreply()
#print "Headers: ", header
res = service.getfile().read()
#print 'Content: ', res
return statuscode,statusmessage,header,res
def do_wls_http_get(url,verb):
return do_http_request(WLS_HOST,WLS_PORT,url,verb,"application/json",WLS_USERNAME,WLS_PASSWORD,"")
def get_links(body):
uris = []
json_obj = {}
json_obj = json.loads(body)
if json_obj.has_key("links"):
for link in sorted(json_obj["links"]):
if (link["rel"] != "parent"):
uri = link["uri"]
uriparsed = urlparse(uri)
uris.append(uriparsed.path)
return uris
def get_links_recursive(body):
uris=[]
links = get_links(body)
for link in links:
statuscode,statusmessage,header,res = do_wls_http_get(link,"GET")
if statuscode==200:
print link
get_links_recursive(res)
statuscode,statusmessage,header,res= do_wls_http_get("/management/wls/latest/","GET")
if statuscode != 200:
print "HTTP statuscode: "+str(statuscode)
print "Have you enabled RESTful Management Services?"
else:
get_links_recursive(res)
Output of this script on a WebLogic 12.1.3 server contains information on all datasources, application deployments, servers and jobs. You can use it to for example compare two environments for the presence of resources. The script is easily expanded to include the configuration of individual resources. This way you can easily compare environments and see if you have missed a specific configuration setting. Of course, only resources are displayed which can be accessed by the RESTful Management Services. Absence of for example a data-source or application deployment can easily be detected but absence of a credential store or JMS queue will not be detected this way. The links are parsed in order (sorted) to help in comparing. You can also use this script to compare WebLogic Server versions to see what new resources Oracle has added since the last release.
No comments:
Post a Comment