Provides a set of methods for running scripts on a schedule.
The instance is created automatically when the script is called and is available through the scheduler
variable.
Takes a table of arguments (array of keys-values).
Parameter | Example | Default value | Description |
---|---|---|---|
method | "POST" | "GET" | Allowable (according to 4.3 RFC 7231 (opens new window)) HTTP 1.1 method for making a request. |
uri | "http://smon.monq.ru" | Absent | Acceptable (according to RFC 2396 (opens new window)) URI of resourse. |
body | "[{ "key": "value" }]" | Absent | The body of the request. An arbitrary string. |
mediaType | "application/json" | "text/plain" | MIME-types -- data types that can be transmitted over the Internet using the MIME standard. |
headers | { ["accept-encoding"] = "gzip, deflate" } | Absent | A table of keys and their values (array of keys-values). |
proxy | { address = "http://1.1.1.1:8080", bypassList = { "http://url1", "http://url2" }, credentials = { username = "guest", password = "guest" } } | Absent | Request proxying settings.address – Acceptable (according to RFC 2396 (opens new window)) URI of resource.bypassList – an array of addresses or regular expressions describing addresses that will not use a proxy for requests to them.credentials – credentials for authentication on the proxy server:username – user name.password – user password. |
basicAuth | { login = "guest", password = "guest" } | Absent | Basic authorization settings for the request.login – user name.password – user password. |
If an error occurs, then data = nil
, err ~= nil
. If the response is normal, then data ~= nil
, err = nil
.
{
data = {
statusCode = 200,
headers = {
["Server"] = "nginx/1.10.3",
["Date"] = "Wed, 16 Oct 2019 07:00:09 GMT"
},
content = "content string",
isSuccessStatusCode = true
},
err = {
message = "Ошибка"
}
}
Basic authorization through an open proxy:
local args =
{
uri = "https://jigsaw.w3.org/HTTP/Basic/",
proxy = {
address = "http://212.220.216.70:8080"
},
basicAuth = {
login = "guest",
password = "guest"
}
}
local response = curl(args)
if (response.err ~= nil) then
print(response.err)
return -- Exit the script early if an error occurs
end
if (response.data.isSuccessStatusCode) == true then
print(response.data.content)
else
print(":( status code " .. response.data.statusCode)
end
Takes a table of arguments (array of keys-values).
Parameter | Type | Example | Default value |
---|---|---|---|
host | string | "http://sample.ssh.com/" | Absent |
port | number | 23 | 22 |
username | string | "demo-user" | Absent |
password | string | "demo-password" | Absent |
privateKey | string | "0KHQtdC60YDQtdGC0L3QvtC1INC/0L7RgdC70LDQvdC40LUgO15Q" | Absent |
command | string | echo "I have a bad feeling about this." | Absent |
local args =
{
host = "sample.ssh.com",
command = "ls /tmp/doc"
}
local response = ssh(args)
if response.data.exitStatus == 0 then
print(response.data.result)
else
print(":( error " .. response.data.error)
end
Sends messages to an email server.
Parameter | Example | Default value |
---|---|---|
ip | "64.233.163.94" | Absent |
community | "public" | "public" |
version | "2c" | "1" |
level | "authnopriv" | "noauthnopriv" |
method | "walk" | "get" |
timeout | 10000 | 1000 |
maxrepetitions | 1 | 10 |
mode | "subtree" | "all" |
data | "s Shanghai" | Absent |
oid | "1.3.6.1.2.1.1.6.0" | Absent |
user | "privacy" | "" |
contextname | "" | "" |
authentication | "md5" | "" |
authphrase | "authentication" | "" |
privphrase | "privacyphrase" | "" |
Sophisticated snmpget of version 3:
local args =
{
ip = "192.168.10.1",
oid = "1.3.6.1.2.1.1.1.0",
version = 3,
level = "authPriv",
authentication = "authentication",
privphrace = "privacyphrase",
user = "privacy"
}
local response = snmp(args)
print(response.data)
Simple snmpwalk of version 1:
local args =
{
ip = "192.168.10.1",
community = "public",
oid = "1.3.6.1.2.1.1.1.0",
method = "walk",
mode = "subtree",
maxrepetitions = 5
}
local response = snmp(args)
print(response.data)
Parameter | Example | Description |
---|---|---|
host | The address of the sending server (IP address or DNS name) | |
port | 25 | Port number on the server |
secureMode | "None" / "Auto" / "SslOnConnect" / "StartTls" / "StartTlsWhenAvailable" | Forces the encryption mode. |
username | Username of the sender (optional, if available, authentication is performed on the server). | |
password | Sender user password (optional). | |
subject | Letter subject | |
body | Text of the letter | |
mailType | Message display type (plain , html ) | |
from | { title = "Notifications department", address = "sender@server.net" } | Sender address (must match the format of the email address, if it doesn't match, the script will end with an error) |
recipients | { "overwatchers@gmail.com", "overwatchers@ya.ru", "tester@gmail.com" } | List of recipient addresses (addresses that do not match the email address format will be excluded from the mailing list) |
On success, data = true
.
If an error occurs, data = false
,err
- an exception object with an error message error.Message
.
Sending a message to one recipient:
local = smtp({
host = "server.mail.ru",
port = 25,
useSsl = true,
username = "user",
password = "pass",
subject = "Event notification",
body = "Dear participants, ...",
mailType = "plain",
from = "sender@server.net",
recipients = "overwatchers@server.com"
})
if (response.data) == false then print(response.err) end
Checks if the specified input string matches the specified regular expression.
input
– input string.pattern
– regular expression (PCRE dialect).true
– if it matches.false
– if does not match.regexIsMatch("user@mailbox.net", "(\\w+@[a-zA-Z_]+?\\.[a-zA-Z]{2,6})")
Searches for the first occurrence of the specified regular expression in the specified input string .
input
– input string.pattern
– regular expression (PCRE dialect).Match
– see documentation (opens new window)Prints all email addresses contained in a string to the console:
local result = regexMatch([[test1@test.com test2 test3@test.com test4@test4com]], [[(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})]])
while result.Success == true do
print (result.Value)
result=result:NextMatch()
end
Replaces all substrings in the input string that match the specified regular expression with the specified value.
input
– input string.pattern
– regular expression (PCRE dialect).replacement
– replacement string.string
– string with the replaced substrings.Replaces all found email addresses with the string email
:
local result = regexReplace([[test1@test.com test2 test3@test.com test4@test4com]], [[(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})]], [[email]])
print (result)
Splits the input string into an array of substrings at positions specified by a regular expression pattern.
input
– input string.pattern
– regular expression (PCRE dialect).string[]
– array of substrings.Splits the input string into an array of email addresses:
local result = regexSplit([[test1@test.com test2 test3@test.com test4@test4com]], [[(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})]])
for i = 0, result.Length-1 do
print (result:GetValue(i))
end
Schedule a script launch after <seconds>
seconds, starting from the moment the method was called.
seconds
– the number of seconds after which the script will be launched, starting from the moment the method was called.LuaResult<boolean>
– result of the method execution.True
– the script is scheduledFalse
– there were problems with submitting the script to the scheduler.result.err
– error details.GET request to get a JSON resource at a given path:
if (isScheduled == true) then
print("The script was launched by the scheduler.")
else
scheduler:executeAfter(60) -- Schedule script execution 60 seconds after calling this method
print("The script has been scheduled.")
end