Configure MID Web Server for metric data

Configure the MID Web Server extension to enable external clients to push metric data to the MID Server. This extension is used to listen for raw metric data as well as external events and it provides options for authentication and data security.

Before you begin

Role required: evt_mgmt_admin

About this task

You can configure the MID Web Server to collect raw metric data by the MID Server and then transmit it to the instance. The MID Web Server extension runs for as long as it is enabled. The extension starts a web server on the MID Server to serve web requests from external systems. The raw data is pushed to the extension from a client or by using customized script.

Procedure

  1. Configure a MID Web Server. For more information, see Configure the MID Web Server extension.
  2. Configure the authentication and secure connection settings, as required.
  3. Click Save to save the Operational Metric data.
  4. Under Related Links click Start to start the collector.
    Table 1. Commands in the MID Web Server form
    Related Link Description
    Start If it is not running, starts the MID Web Server.
    Stop Stops the MID Web Server. If the collector is not running, no action is taken.
    Restart Stops, then starts the MID Web Server.
    Test parameters The test is not relevant to Operational Metrics. Parameters are not tested or validated when Test is run.
    Update parameters Stops and then starts the MID Web Server with new parameters. If none of the parameters are modified, no update is made.

Example

Create an authentication token to be sent with each request.

Method: Create a token by constructing a string using defined elements of the HTTP/HTTPS request. Then create an HMAC (Hash Message Authentication Code) of the string by signing the generated string with the auto-generated secret key that is displayed in the Secret Key. This key is unique per context. Send this authentication token in the request header Authorization.

Data for the example:

Table 2. Keybased authentication data
Item Value
Path to a web service API for sending raw data Use the URL in this format:https://<instance>/api/mid/sa/metrics For example: https://mid1.service-now.com/api/mid/sa/metrics
Request type POST
Date format
yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
For example: 2016-06-08T20:54:58.917Z
Content-Type application/json

Use the following request elements to generate the required string: HTTP-Verb, Content-Type, Date, and request path. Specify these elements and place them in this order:

  • HTTP-Verb + "\n" +
  • Content-Type + "\n" +
  • Date + "\n" +
  • Request-Path

For this example, the request string is:

POST\napplication/json\n2016-06-08T20:54:58.917Z\n/api/mid/sa/metrics

For the timestamp requirement, a valid timestamp that uses HTTP date header is required for authenticating the request. Ensure that the timestamp is within 15 minutes of the MID Server.

Example, using Java, that describes how to generate the HMAC of the string that uses defined elements of the HTTP/HTTPS request.

package sample;
import com.glide.util;
import java.security.SignatureException;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class AuthUtil {
	
private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";

/***
 * Generates base64-encode the HMAC(Hash Message Authentication Code) of input data
 * 
 * @param data
 * @param key
 * @return
 * @throws java.security.SignatureException
 */
public static String signData(String data, String key) throws java.security.SignatureException {
	String result;
	try {
		// get an hmac_sha1 key from the raw key bytes
		SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);

		// create hmac_sha1 Mac instance and initialize with the signing key
		Mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
		mac.init(signingKey);

		// compute the hmac on input data bytes
		byte[] rawHmac = mac.doFinal(data.getBytes("UTF-8"));

		// base64-encode the hmac
		result = Base64.encode(rawHmac);

	} catch (Exception e) {
		throw new SignatureException("Failed to generate HMAC : " + e.getMessage());
	}
	return result;
}
}