/// <summary> /// This action is used to add a new External monitor. /// </summary> /// <param name="type">type of the test</param> /// <param name="name">the name of the test</param> /// <param name="url">url of the test</param> /// <param name="interval">check interval(min)</param> /// <param name="tag">tag of the test</param> /// <param name="detailedTestType">specifies the request method. Used for HTTP and HTTPS. Default value is GET. </param> /// <param name="timeout">test timeout in ms. Default value is 10000</param> /// <param name="overSSL">if true, requests will be sent via SSL. Can be set for FTP, UDP, TCP, SMTP, IMAP, POP test types.</param> /// <param name="postData">data to send during POST request, e.g m_U=asd&m_P=asd</param> /// <param name="contentMatchFlag">set to true if there is string to match in response text otherwise false.</param> /// <param name="contentMatchString">text to match in the response</param> /// <param name="testParams">additional test parameters /// TODO: http://monitis.com/api/api.html#addExternalMonitor - create type for MySQL and DNS?</param> /// <param name="uptimeSLA">min allowed uptime(%)</param> /// <param name="responseSLA">max allowed response time in seconds</param> /// <param name="basicAuthUser">userName for authentication</param> /// <param name="basicAuthPass">password for authentication</param> /// <param name="output">Output type - JSON or XML</param> /// <param name="validation">HMACSHA1 for checksum validation or token for authToken validation</param> /// <param name="locationIds">comma separated ids of the locations to add test for</param> /// <returns>Add ExternalMonitor Response</returns> public AddExternalMonitorResponse AddMonitor( TestType type, string name, string url, CheckInterval interval, string tag, int[] locationIds, DetailedTestType detailedTestType = DetailedTestType.GET, int timeout = 10000, bool? overSSL = null, string postData = null, bool? contentMatchFlag = null, string contentMatchString = null, Dictionary<string, string> testParams = null, int? uptimeSLA = null, int? responseSLA = null, string basicAuthUser = null, string basicAuthPass = null, OutputType? output = null, Validation? validation = null) { OutputType outputType = GetOutput(output); var parameters = new Dictionary<string, object>(); parameters.Add(Params.name, name); parameters.Add(Params.tag, tag); parameters.Add(Params.locationIds, String.Join(",", locationIds)); parameters.Add(Params.url, url); parameters.Add(Params.type, type); parameters.Add(Params.interval, (int) interval); /*minutes - int value*/ AddIfNotNull(parameters, Params.contentMatchString, contentMatchString); AddIfNotNull(parameters, Params.contentMatchFlag, Helper.BoolToInt(contentMatchFlag)); AddIfNotNull(parameters, Params.basicAuthUser, basicAuthUser); AddIfNotNull(parameters, Params.basicAuthPass, basicAuthPass); AddIfNotNull(parameters, Params.postData, postData); if (null != testParams && testParams.Count > 0) { string testParamsString = Helper.MapToURLString(testParams); AddIfNotNull(parameters, Params.@params, testParamsString); } parameters.Add(Params.detailedTestType, (int) detailedTestType); AddIfNotNull(parameters, Params.timeout, timeout); AddIfNotNull(parameters, Params.uptimeSLA, uptimeSLA); AddIfNotNull(parameters, Params.responseSLA, responseSLA); AddIfNotNull(parameters, Params.overSSL, Helper.BoolToInt(overSSL)); RestResponse response = MakePostRequest(ExternalMonitorAction.addExternalMonitor, parameters, output: outputType, validation: validation); Helper.CheckStatus(response, output: outputType); var addExternalMonitorResponse = new AddExternalMonitorResponse(); //Fill information from response to struct Int32.TryParse(Helper.GetValueOfKey(response, Params.isTestNew, outputType), out addExternalMonitorResponse.isTestNew); Int32.TryParse(Helper.GetValueOfKey(response, Params.testId, outputType), out addExternalMonitorResponse.testId); DateTime.TryParse(Helper.GetValueOfKey(response, Params.startDate, outputType), out addExternalMonitorResponse.startDate); return addExternalMonitorResponse; }
/// <summary> /// This action is used to add a new External monitor. /// </summary> /// <param name="type">type of the test</param> /// <param name="name">the name of the test</param> /// <param name="url">url of the test</param> /// <param name="interval">check interval(min)</param> /// <param name="tag">tag of the test</param> /// <param name="detailedTestType">specifies the request method. Used for HTTP and HTTPS. Default value is GET. </param> /// <param name="timeout">test timeout in ms. Default value is 10000</param> /// <param name="overSSL">if true, requests will be sent via SSL. Can be set for FTP, UDP, TCP, SMTP, IMAP, POP test types.</param> /// <param name="postData">data to send during POST request, e.g m_U=asd&m_P=asd</param> /// <param name="contentMatchFlag">set to true if there is string to match in response text otherwise false.</param> /// <param name="contentMatchString">text to match in the response</param> /// <param name="testParams">additional test parameters /// TODO: http://monitis.com/api/api.html#addExternalMonitor - create type for MySQL and DNS?</param> /// <param name="uptimeSLA">min allowed uptime(%)</param> /// <param name="responseSLA">max allowed response time in seconds</param> /// <param name="basicAuthUser">userName for authentication</param> /// <param name="basicAuthPass">password for authentication</param> /// <param name="output">Output type - JSON or XML</param> /// <param name="validation">HMACSHA1 for checksum validation or token for authToken validation</param> /// <param name="locationIds">comma separated ids of the locations to add test for</param> /// <returns>Add ExternalMonitor Response</returns> public AddExternalMonitorResponse AddMonitor( TestType type, string name, string url, CheckInterval interval, string tag, int[] locationIds, DetailedTestType detailedTestType = DetailedTestType.GET, int timeout = 10000, bool?overSSL = null, string postData = null, bool?contentMatchFlag = null, string contentMatchString = null, Dictionary <string, string> testParams = null, int?uptimeSLA = null, int?responseSLA = null, string basicAuthUser = null, string basicAuthPass = null, OutputType?output = null, Validation?validation = null) { OutputType outputType = GetOutput(output); var parameters = new Dictionary <string, object>(); parameters.Add(Params.name, name); parameters.Add(Params.tag, tag); parameters.Add(Params.locationIds, String.Join(",", locationIds)); parameters.Add(Params.url, url); parameters.Add(Params.type, type); parameters.Add(Params.interval, (int)interval); /*minutes - int value*/ AddIfNotNull(parameters, Params.contentMatchString, contentMatchString); AddIfNotNull(parameters, Params.contentMatchFlag, Helper.BoolToInt(contentMatchFlag)); AddIfNotNull(parameters, Params.basicAuthUser, basicAuthUser); AddIfNotNull(parameters, Params.basicAuthPass, basicAuthPass); AddIfNotNull(parameters, Params.postData, postData); if (null != testParams && testParams.Count > 0) { string testParamsString = Helper.MapToURLString(testParams); AddIfNotNull(parameters, Params.@params, testParamsString); } parameters.Add(Params.detailedTestType, (int)detailedTestType); AddIfNotNull(parameters, Params.timeout, timeout); AddIfNotNull(parameters, Params.uptimeSLA, uptimeSLA); AddIfNotNull(parameters, Params.responseSLA, responseSLA); AddIfNotNull(parameters, Params.overSSL, Helper.BoolToInt(overSSL)); RestResponse response = MakePostRequest(ExternalMonitorAction.addExternalMonitor, parameters, output: outputType, validation: validation); Helper.CheckStatus(response, output: outputType); var addExternalMonitorResponse = new AddExternalMonitorResponse(); //Fill information from response to struct Int32.TryParse(Helper.GetValueOfKey(response, Params.isTestNew, outputType), out addExternalMonitorResponse.isTestNew); Int32.TryParse(Helper.GetValueOfKey(response, Params.testId, outputType), out addExternalMonitorResponse.testId); DateTime.TryParse(Helper.GetValueOfKey(response, Params.startDate, outputType), out addExternalMonitorResponse.startDate); return(addExternalMonitorResponse); }