This example shows the use of JavaScript with the vSphere Automation SDK for REST to request the overall system health indicator for the vCenter Server Appliance.

The example assumes a previously existing session with the vSphere Automation API endpoint. The JavaScript code depends on the Node.js package.

This example depends on the following global variables.

my_http_options

var https = require('https');
var httpPort = 443;
var httpPath = '/rest/appliance/health/system';
var httpMethod = 'GET';

// Prepare the HTTP request.
my_http_options = session.my_http_options;
my_http_options.method = httpMethod;
my_http_options.path = httpPath;

// Define the callbacks.
function callback(res) {
  res.on('error',
         function(err) {console.log('ERROR checking system health: ', err)});
  res.on('data', function(chunk) {data = chunk.toString();});
  res.on('end', function() {
    if (res.statusCode == 200) {
      console.log('Overall system health status: ', JSON.parse(data).value);
    }
  })
};

// Issue the request.
https.request(my_http_options, callback).end();