In some cases, you may not be able to connect to SAAS's dialing task service. In this case, we can define the dialing task through the local JSON file.
Go to the conf.d/network directory under the DataKit installation directory, copy dialtesting.conf.sample and name it dialtesting.conf. Examples are as follows:
[[inputs.dialtesting]]server="file://</path/to/your/local.json>"# Note: Taking Linux as an example, assuming your json directory is /some/path/my.json, then the# server should be written as file:///some/path/my.json# Note that the following tag suggestions are filled in one by one (do not modify the tag key here), so that the complete dialing test results can be displayed on the page.[inputs.dialtesting.tags]country="<specify-datakit-country>"# Countries where DataKit is deployedprovince="<specify-datakit-province>"# Provices where DataKit is deployedcity="<specify-datakit-city>"# Cities where DataKit is deployedisp="<specify-datakit-ISP>"# Specify the network service provider where DataKit is locatedregion="<your-region>"# You can specify a region name at will
The specific country/region and ISP selection can be selected as shown in the following figure (note that you don't really create a new "self-built node", just provide an alternative source here):
After editing this JSON, it is recommended to find some(online tools or this tool)to verify that the JSON format is correct. If the JSON format is incorrect, the dialing test will not take effect.
The public fields of dialing test tasks are defined as follows:
Field
Type
Whether Required
Description
name
string
Y
Dial test service name
status
string
Y
Dial test service status, such as "OK"/"stop"
frequency
string
Y
Dial frequency
success_when_logic
string
N
The logical relationship between success_when conditions, such as "and"/"or", defaults to "and"
success_when
object
Y
See below for details
advance_options
object
N
See below for details
post_url
string
N
Send the dialing test result to the workspace pointed by the Token, and if it is not filled in, send it to the workspace where the current DataKit is located
Here, body can configure multiple verification rules, and the relationship between them is determined by "success_when_logic". When it is configured as and, if any rule is verified, it will be considered that the current dialing test failed; When it is configured to or, if any rule is verified, it will be considered that the current dialing test is successful. The default is an and relationship. The following verification rules all follow this judgment principle.
Note that the regular is escaped correctly here, and the actual regular expression in the example is \d\d.*.
HTTP request returns header judgment (header)
Field
Type
Whether Required
Description
is
string
N
The header returned specifies whether the field is equal to the specified value
is_not
string
N
The header returned specifies whether the field is not equal to the specified value.
match_regex
string
N
The header returned specifies whether the field contains a substring of the matching regular expression.
not_match_regex
string
N
The header returned specifies whether the field does not contain a substring of the matching regular expression.
contains
string
N
The header returned specifies whether the field contains the specified substring.
not_contains
string
N
The header returned specifies whether the field does not contain the specified substring.
Whether the status code returned is equal to the specified field
is_not
string
N
Whether the status code returned is not equal to the specified field
match_regex
string
N
Whether the status code returned contains a substring of the matching regular expression
not_match_regex
string
N
Whether the status code returned does not contain a substring of the matching regular expression
contains
string
N
Whether the status code returned contains the specified substring
not_contains
string
N
Whether the status code returned does not contain the specified substring
for example:
"success_when":[{"status_code":[{"is":"200"}]}]
For a certain URL dial test, its HTTP return is usually only one, so only one validation rule is generally configured here (although multiple array configurations are supported).
HTTP request response time (response_time)
Only one time value can be filled in here. If the response time of the request is less than the specified value, the dialing test is judged to be successful, such as:
"success_when":[{"response_time":"100ms"}]
Note that the time units specified here are ns (nanoseconds)/us (microseconds) /ms (milliseconds) /s (seconds) /m (minutes) /h (hours). For HTTP dial testing, ms units are generally used.
Several kinds of judgment basis listed above can be used in combination, and the relationship between them is determined by "success_when_logic". When it is configured as and, if any rule is verified, it is considered that the current dialing test fails; When it is configured to or, if any rule is verified, it will be considered that the current dialing test is successful; The default is an and relationship. Such as:
To facilitate the processing of HTTP responses by post_script and to enable the determination of test results and the extraction of variables, certain predefined variables can be utilized when composing the script. These are detailed as follows:
response: the response object of the HTTP request
Field
Type
Description
status_code
number
status code
header
json
response header {"header1": ["value1", "value2"]}
body
string
response body
result: the test result
Field
Type
Description
is_failed
bool
failed or not
error_message
string
error message
vars: the variable object to store the extracted variables
A JSON object where the key represents the variable name and the value represents the variable value. For example: vars["token"] = "123"
In the above example, the response content is initially parsed into a JSON object using load_json. Subsequently, it checks whether the response status code is 200. If it is, the token from the response content is extracted and assigned to the variable vars. If the status code is not 200, the is_failed attribute of result is set to true, and the error_message is assigned the message from the response content.