1<!DOCTYPE html> 2<html> 3<head> 4 <script type="text/javascript"> 5 // This simple example subscribes, via websocket, to certain events occurring 6 // on the BMC. Specfically, it's interested in an d-bus events (object 7 // creations, property changes), occurring in the d-bus namespaces 8 // /xyz/openbmc_project/logging and /xyz/openbmc_project/sensors. It's also 9 // interested in the interfaces xyz.openbmc_project.Logging.Entry and 10 // xyz.openbmc_project.Sensor.Value being added, or property changes to 11 // these interfaces. 12 13 14 // Insert code here to log-on to the BMC. At the moment of writing this 15 // example, I don't know how to do that in javascript (I had disabled the 16 // the authorization plug-in in rest_dbus.py to test this example). See 17 // https://github.com/openbmc/docs/blob/master/rest-api.md for the log-on 18 // API. 19 20 // Open a new secure websocket. The rest server on the BMC 21 // only supports the /subscribe route with websockets as of now. 22 var ws = new WebSocket("wss://<BMC IP>/subscribe"); 23 // Send in array of d-bus paths and interfaces of interest over the 24 // websocket. Either/both of them can be an empty array. The arrays 25 // need to be sent in a JSON dictionary. 26 // Client will be notified of events occurring on these paths and/or 27 // interfaces. 28 var data = JSON.stringify( 29 { 30 "paths": ["/xyz/openbmc_project/logging", 31 "/xyz/openbmc_project/sensors"], 32 "interfaces": ["xyz.openbmc_project.Logging.Entry", 33 "xyz.openbmc_project.Sensor.Value"] 34 }); 35 ws.onopen = function() { 36 // Send the JSON dictionary 37 ws.send(data); 38 }; 39 ws.onmessage = function (evt) { 40 // Received a message on the websocket, the response is a JSON dict. 41 var response = JSON.parse(evt.data); 42 for (var key in response) { 43 if (response.hasOwnProperty(key)) { 44 var value = response[key]; 45 if ("path" == key) { 46 // If the d-bus path is in the response, let's do a GET on 47 // that path. 48 var xhr = new XMLHttpRequest(); 49 var url = "https://<BMC IP>" + value; 50 xhr.open("GET", url, true); 51 xhr.setRequestHeader("Content-type", "application/json"); 52 xhr.send(); 53 } 54 } 55 } 56 }; 57 </script> 58</head> 59</html> 60