ki
name: "TestKi"
version: "0@NoName"
description: "Just a simple test KI"
on
NodeType # exists
not NodeFoo # not exists
(NodeType == "Machine")
OSName =~ "(SLES|Centos)"
(OSVersion > "7") and (OSVersion < "10") # or OSVersion in 7..10 ?
with Type@in as ParentScope
(NodeType == "Resource") or (NodeType == "Software")
MonitoringEnabled
end
when
VarA
VarB["key"] # match on key
VarC[VarA] == NodeType
list VarD
VarF as Test
MonitoringStatus@in == "true"
do
log.info("bind ki and execute do")
VarB["new_key"] = 1
add(NewVar["key"] = "1")
delete(VarA)
stdout: ExecuteOutput, exit: LOCAL::Error = execute("path/to/script", timeout: 60)
if Error then
log.error("command returned non-zero exit code")
else
log("execute returned ${ExecuteOutput}")
end
Table of Contents
1.Full Example
2.Retry action KI
ki
name: "TestKi"
version: "0@NoName"
description: "This KI will retry execution up to three times upon AH failure"
on
ogit/name == "default_issue_node"
when
ProcessIssue
ticketId == "IN-XXXXX"
? counter < 3 := 0
ogit/Automation/processingTimestamp
do
#AH to the Solve ticket
LOCAL::SYSTEMRC = "1"
if LOCAL::SYSTEMRC == "0" then
delete(ProcessIssue)
else
log.error("process ticket failed")
counter = counter + 1
log(counter)
end
3.Add Comment to ticketing System (Valuemation)
ki
name: "TestKi"
version: "0@NoName"
description: "Update the ticket with a comment stored directly in the ToDo AddComment"
on
ogit/name == "default_issue_node"
when
AddComment
ticketId
valEnterpriseId
do
# Call to update a Ticket in Valuemation with a ticket message
body: LOCAL::BODY,
code: LOCAL::CODE,
headers: LOCAL::HEADERS,
exit: LOCAL::ACTIONSYSTEMRC = action(capability: "UpdateTicket",
mainDescription: "ticket description",
ticketNo: "${ticketId}",
descriptionBody: "${AddComment}",
descriptionTitle: "Updating ticket",
tenantId: "${valEnterpriseId}"
)
if LOCAL::CODE == "200" then
delete(AddComment)
else
log("Updating ticket failed")
end
4. Fallback KI to trigger when a task remains unresolved
ki
name: "TestKi"
version: "0@NoName"
description: "KI to be trigger before the datagroup.de:Default:AutoStopIdleIssues KI, it will forward the ticket to the responsible support Group for manual resolution"
tier: "fallback"
on
ogit/name == "default_issue_node"
when
? ogit/Automation/maxIdleTime@any := 6
ExecIdle > ogit/Automation/maxIdleTime
ticketId
assignmentGroup == "Bardioc"
responsibleSupportGroup
description
do
body: LOCAL::BODY,
code: LOCAL::CODE,
headers: LOCAL::HEADERS,
exit: LOCAL::ACTIONSYSTEMRC = action(capability: "ForwardTicket",
ticketNo: "${ticketId}",
supportGroup: "${responsibleSupportGroup}",
description: "${description}"
)
# result interpretation
if LOCAL::CODE == "200" then
log("Forwarded to support group")
else
log("Forward Ticket to support group failed")
end
5. Checking Spelling
ki
name: "TestKi"
version: "0@NoName"
description: "Before start any further steps you have to check if the first and last name contains special letter like ä,ö,ü or accent mark\. If so you have to remove or correct it"
tier: "fallback"
on
ogit/name == "default_issue_node"
when
CheckSpelling
vorname
do
exit: LOCAL::EXIT, result: LOCAL::vor = javascript('
spechrs = { "ä" : "ae", "ö" : "oe", "ü" : "ue", "ß" : "ss",
"Ä" : "Ae", "Ö" : "Oe", "Ü" : "Ue",
"á" : "a", "â" : "a", "Á" : "A", "Â" : "A",
"é" : "e", "ê" : "e", "É" : "E", "Ê" : "E",
"í" : "i", "î" : "i", "Í" : "I", "Î" : "I",
"ó" : "o", "ô" : "o", "Ó" : "O", "Ô" : "O",
"ú" : "u", "û" : "u", "Ú" : "U", "Û" : "U",
}
str = "${vorname}"
for(chr in spechrs)
{
str = str.replace(new RegExp(chr,"g"),spechrs[chr])
}
str
')
# result interpretation
if LOCAL::EXIT == "0" then
vorname = LOCAL::vor
log("Name has been reviewed")
delete(CheckSpelling)
else
log("Failed to check Name spelling")
end
6. Working with dates
ki
name: "TestKi"
version: "0@NoName"
description: "example on how to manipulate dates"
on
ogit/name == "default_issue_node"
when
ProcessIssue
do
# Displays current date into a given date format
result: LOCAL::DATE = dateprint(format: "%A, %Oe, %B, %Y %H:%M:%S")
log("Current date formatted as: Weekday, Day of the Month, Month, Year Time: ${LOCAL::DATE}")
# Converts date into timestamp
LOCAL::DATE1 = "2024-11-05T18:00"
result: LOCAL::DATEMS = javascript("
let date = new Date(`${DATE1}`).getTime();
date;
")
log("Date as a timestamp: ${LOCAL::DATEMS}")
# Convert timestamp to a given date format
result: date = dateprint(timestamp: LOCAL::DATEMS, format: "%d.%m.%Y")
log("Date formatted as: Day.Month.Year ${date}")
7. Querying Graph
ki
name: "TestKi"
version: "0@NoName"
description: "example on how to query the graph"
on
ogit/name == "default_issue_node"
when
GraphQuery == "Graph Query 1"
do
# Graph Query
# LOCAL::NODEID contains the list of found ogit/_id
LOCAL::NODEID = ""
exit: LOCAL::EXIT,
output: LOCAL::OUTPUT = query('vertices', 'ogit\/_type:ogit\/MARS\/Machine ',
fields: "ogit/_id",
each: begin
LOCAL::NODEID = "${ogit/_id}"
log(LOCAL::NODEID)
end
)
# result interpretation
if LOCAL::EXIT == "0" then
delete(GraphQuery)
else
log("Failed to complete the query")
end
8. Approval AH KI
Visit the whole guide about the approval AH here
9. Writing Atomic KIs
Please see a full example in here