{"componentChunkName":"component---src-templates-default-template-tsx","path":"/ki-syntax/definitions/ki-structure/","result":{"data":{"asciidoc":{"id":"edbec38b-2e73-58db-847f-f84a8441430c","html":"<div id=\"toc\" class=\"toc\">\n<div id=\"toctitle\">Table of Contents</div>\n<ul class=\"sectlevel1\">\n<li><a href=\"#_introduction\">Introduction</a></li>\n<li><a href=\"#_sections\">Sections</a>\n<ul class=\"sectlevel2\">\n<li><a href=\"#ki\">ki</a>\n<ul class=\"sectlevel3\">\n<li><a href=\"#KI.tiers\">KI Tiers</a></li>\n</ul>\n</li>\n<li><a href=\"#on\">on</a>\n<ul class=\"sectlevel3\">\n<li><a href=\"#on.with\">Related Node Matching</a></li>\n</ul>\n</li>\n<li><a href=\"#when\">when</a></li>\n<li><a href=\"#do\">do</a>\n<ul class=\"sectlevel3\">\n<li><a href=\"#branching-if\">Logical Branching</a></li>\n</ul>\n</li>\n</ul>\n</li>\n<li><a href=\"#comments\">Comments</a></li>\n</ul>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_introduction\">Introduction</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>Knowledge Items use a YAML-like syntax and are constructed using five major sections. The following document will introduce you to each section and how it is used.</p>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_sections\">Sections</h2>\n<div class=\"sectionbody\">\n<div class=\"admonitionblock important\">\n<table>\n<tr>\n<td class=\"icon\">\n<i class=\"fa icon-important\" title=\"Important\"></i>\n</td>\n<td class=\"content\">\n<div class=\"paragraph\">\n<p>Mandatory elements for all KI are: <code>ki</code>, <code>name</code> and <code>​on</code>​. Each KI must additionally have at least the combination​ <code>​when</code>​ and <code>​do</code>​.</p>\n</div>\n</td>\n</tr>\n</table>\n</div>\n<div class=\"paragraph\">\n<p>Every Knowledge Item is build with these sections:</p>\n</div>\n<table class=\"tableblock frame-all grid-all stretch\">\n<caption class=\"title\">Table 1. KI sections</caption>\n<colgroup>\n<col style=\"width: 50%;\">\n<col style=\"width: 50%;\">\n</colgroup>\n<thead>\n<tr>\n<th class=\"tableblock halign-left valign-top\">Section</th>\n<th class=\"tableblock halign-left valign-top\">Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\"><code>ki</code></p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Meta information about the KI, like <code>name</code>, <code>description</code> and <code>version</code></p></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\"><code>on</code></p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Specifies on which node the knowledge will be applied and which conditions should exist on the node</p></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\"><code>when</code></p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Specifies which conditions should exist on the issue to execute the KI</p></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\"><code>do</code></p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Commands to execute in the case of issue binding</p></td>\n</tr>\n</tbody>\n</table>\n<div style=\"page-break-after: always;\"></div>\n<div class=\"sect2\">\n<h3 id=\"ki\">ki</h3>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><code>name</code> - KI Name (if KIs are saved to the filesystem, this name should be the same as the filename)</p>\n</li>\n<li>\n<p><code>description</code> - KI description</p>\n</li>\n<li>\n<p><code>version</code> - (<strong>Mandatory Attribute</strong>), defines the version of the KI. Proposed form is: <code>1@author</code> (this should allow to modify the KI in a distributed environment by different people, but still allows easier update later. For example, if the author doesn&#8217;t change, then <code>1@Foo</code> should be updated to <code>2@Foo</code>, but <code>2@Foo</code> and <code>3@Bar</code> would be in conflict, needing manual resolving)</p>\n</li>\n<li>\n<p><code>tier</code> - Optional attribute to indicate execution tier the KI belongs to (\"default\", \"policy\" or \"fallback\")</p>\n</li>\n</ul>\n</div>\n<div class=\"sect3\">\n<h4 id=\"KI.tiers\">KI Tiers</h4>\n<div class=\"paragraph\">\n<p>KIs can be assigned to one of three priority tiers which will affect KI selection priority.</p>\n</div>\n<table class=\"tableblock frame-all grid-all stretch\">\n<colgroup>\n<col style=\"width: 50%;\">\n<col style=\"width: 50%;\">\n</colgroup>\n<tbody>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">default</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">the normal KI priority which should be used for almost all normal KIs</p></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">policy</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">the policy level will guarantee execution before KIs of the other tiers</p></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">fallback</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">KIs in this tier will only ever be executed when not default or policy KIs are matching</p></td>\n</tr>\n</tbody>\n</table>\n<div class=\"paragraph\">\n<p>KI tiers are <em>only</em> applied on a vertex local scope, so a matching \"fallback\" KI on the current processing vertex will be executed before the issue is routed to a \"policy\" KI on a connected remote vertex.</p>\n</div>\n<div class=\"paragraph\">\n<p>If the tier is not specified in the KI, it defaults to \"Default\" policy. To assign either of the other two values, you must include the tier attribute with the corresponding value in the KI header.</p>\n</div>\n<div class=\"paragraph\">\n<p>Imagine you have as ToDos \"OpenTicket\", \"CheckUserExists\" and \"ResetPassword\". Among these three Actions, OpenTicket is designated as the initial step to ensure that subsequent results can be reported to the ticketing system for documentation purposes.\nTo prioritize OpenTicket as the first action, we use the tier feature. OpenTicket is a KI that must always be executed first amongst others, to ensure that subsequent steps can be accurately reported to the ticketing system for documentation purposes.</p>\n</div>\n<div class=\"imageblock\">\n<div class=\"content\">\n<img src=\"/7.0/images/ki-syntax/tiers.png\" alt=\"Tiers\">\n</div>\n</div>\n<div class=\"paragraph\">\n<p>The tier must be explicitly stated in the KI header; if left unspecified, the default value for the tier is used.</p>\n</div>\n<div class=\"imageblock\">\n<div class=\"content\">\n<img src=\"/7.0/images/ki-syntax/TierHeader.png\" alt=\"Tier Header\">\n</div>\n</div>\n<div class=\"admonitionblock important\">\n<table>\n<tr>\n<td class=\"icon\">\n<i class=\"fa icon-important\" title=\"Important\"></i>\n</td>\n<td class=\"content\">\nOnly use \"policy\" and \"fallback\" tiers for rare cases where guaranteed prioritized or \"last resort\" execution is absolutely essential.\n</td>\n</tr>\n</table>\n</div>\n<div class=\"listingblock\">\n<div class=\"title\">ki Section Example</div>\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\">ki\n  name: \"Tutorial test KI\"\n  version: \"1@Author\"\n  description: \"Tutorial test KI to describe KI Syntax 6.0\"\n  tier: \"default\"</code></pre>\n</div>\n</div>\n<div style=\"page-break-after: always;\"></div>\n</div>\n</div>\n<div class=\"sect2\">\n<h3 id=\"on\">on</h3>\n<div class=\"paragraph\">\n<p>This section defines where the KI is \"bound\" meaning a definition of\nfilter elements that specify environment conditions according to the\nMARS-Model Node data. It could look something like:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"title\">on Section Example</div>\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\">on\n  NodeType    # exists\n  not NodeFoo # not exists\n  (NodeType == \"Machine\")\n  OSName =~ \"(SLES|Centos)\"\n  (OSVersion &gt; \"7\") and (OSVersion &lt; \"10\") # or OSVersion in 7..10 ?\n  with Type@in as ParentScope\n    (NodeType == \"Resource\") or (NodeType == \"Software\")\n    MonitoringEnabled\n  end</code></pre>\n</div>\n</div>\n<div style=\"page-break-after: always;\"></div>\n<div class=\"sect3\">\n<h4 id=\"on.with\">Related Node Matching</h4>\n<div class=\"paragraph\">\n<p>This subsection provides an additional restriction to the vertices on which <code>ki</code> will be applied. Namely, the vertex which is matched by the regular conditions in <code>on</code> section must additionally be connected to another vertex of type <code>&lt;vertexType&gt;</code> by an connection of type &lt;edgeType&gt; in direction <code>edgeDirection</code>. The &lt;edgeType&gt; can be omitted which would accept any edge type:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"title\">Related Node Matching Syntax Template</div>\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\">with &lt;vertexType&gt;@&lt;edgeDirection&gt;[:&lt;edgeType&gt;]\n  &lt;Conditions&gt;\nend</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>where <code>&lt;edgeDirection&gt;</code> can have the following values: <code>in</code>, <code>out</code>, or <code>connected</code>.</p>\n</div>\n<div class=\"paragraph\">\n<p>It  specifies direction of the edge between vertices, can be incoming (in:&#8592;), outgoing (out:&#8594;) or connected (-). The last one means that condition <code>with</code> is true for any edge direction (in or out), it just checks if edge exists.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"title\">Related Node Matching Syntax Example</div>\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\">on\n  ogit/_type == \"ogit/Person\"\n  with ogit/Software/Application@out:ogit/uses\n    ogit/name == \"LunchApp\"\n    ogit/url\n  end</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>That way <code>KI</code> will execute on every vertex of type \"ogit/Person\" having an outgoing edge of type <code>ogit/uses</code> to a\nvertex of type <code>ogit/Software/Application</code> which must satisfy the following conditions:</p>\n</div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><code>ogit/name</code> attribute has value \"LunchApp\"</p>\n</li>\n<li>\n<p>attribute <code>ogit/url</code> exists</p>\n</li>\n</ul>\n</div>\n<div style=\"page-break-after: always;\"></div>\n</div>\n</div>\n<div class=\"sect2\">\n<h3 id=\"when\">when</h3>\n<div class=\"paragraph\">\n<p>The instructions defined in <code>do</code> will only be executed when <strong>all</strong> conditions\nof <code>when</code> section are matched.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"title\">when Section Example</div>\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\">when\n  VarA\n  VarB[\"key\"] # match on key\n  VarC[VarA] == NodeType\n  list VarD\n  VarF as Test\n  MonitoringStatus@any == \"true\"</code></pre>\n</div>\n</div>\n<div style=\"page-break-after: always;\"></div>\n</div>\n<div class=\"sect2\">\n<h3 id=\"do\">do</h3>\n<div class=\"paragraph\">\n<p>Once all conditions are matched the Knowledge Item will be applied. The\n<code>do</code> section defines which actions are performed. It might look like this:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"title\">do Section Example</div>\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\">  log.info(\"bind ki and execute do\")\n  VarB[\"new_key\"] = 1\n  add(NewVar[\"key\"] = \"1\")\n  delete(VarA)\n  stdout: ExecuteOutput, exit: LOCAL::Error = execute(\"path/to/script\", timeout: 60)\n  if Error then\n    log.error(\"command returned with non-zero exit code\")\n  else\n    log(\"execute returned ${ExecuteOutput}\")\n  end</code></pre>\n</div>\n</div>\n<div class=\"sect3\">\n<h4 id=\"branching-if\">Logical Branching</h4>\n<div class=\"admonitionblock important\">\n<table>\n<tr>\n<td class=\"icon\">\n<i class=\"fa icon-important\" title=\"Important\"></i>\n</td>\n<td class=\"content\">\n<div class=\"paragraph\">\n<p>Designing Knowledge Items with <code>If</code> logic should be avoided. It is much preferred to design atomic Knowledge Items as much as possible.</p>\n</div>\n<div class=\"paragraph\">\n<p>As a rule of thumb: Deciding between variants of a log message is acceptable. Making decisions about the data condition should be handled in a separate and re-usable Knowledge Item.</p>\n</div>\n</td>\n</tr>\n</table>\n</div>\n<div class=\"paragraph\">\n<p>You can use the <a href=\"/7.0/ki-syntax/functions/if/\">If</a> function to add logical branching to your Knowledge Item.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\">do\n  stdout: ExecuteOutput, exit: LOCAL::Error = execute(\"path/to/script\", timeout: 60)\n  if Error then\n    log.error(\"command returned with non-zero exit code\")\n  else\n    log(\"execute returned ${ExecuteOutput}\")\n  end</code></pre>\n</div>\n</div>\n<div style=\"page-break-after: always;\"></div>\n</div>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"comments\">Comments</h2>\n<div class=\"sectionbody\">\n<div class=\"admonitionblock important\">\n<table>\n<tr>\n<td class=\"icon\">\n<i class=\"fa icon-important\" title=\"Important\"></i>\n</td>\n<td class=\"content\">\nSingle line KI will not work with inline comments. If you wish to use comments in your KI definition you MUST use the long form notation.\n</td>\n</tr>\n</table>\n</div>\n<div class=\"paragraph\">\n<p>You can add comments to you Knowledge Items that explain what certain elements are supposed to do. They simply start with a <code>#</code>. Comments can be added virtually anywhere in the definition.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\"># Just a comment\nVarA #This is also a comment</code></pre>\n</div>\n</div>\n<div style=\"page-break-after: always;\"></div>\n<div class=\"admonitionblock note\">\n<table>\n<tr>\n<td class=\"icon\">\n<i class=\"fa icon-note\" title=\"Note\"></i>\n</td>\n<td class=\"content\">\nIf you wish to see how these sections are used you can refer to a <a href=\"/7.0/ki-syntax/definitions/example/\">full example</a>.\n</td>\n</tr>\n</table>\n</div>\n</div>\n</div>","document":{"main":"1.Knowledge Item Structure","title":"1.Knowledge Item Structure","subtitle":""},"fields":{"toc":true,"location":["ki-syntax","definitions","ki-structure"]}},"sidebarYaml":{"id":"6f28bdca-d703-5e79-ae00-b0508f8ee82a","showIndex":true}},"pageContext":{"id":"edbec38b-2e73-58db-847f-f84a8441430c","parent":"ki-syntax"}},"staticQueryHashes":["1010459453","1010459453","2356112386","2356112386","2603905930","2603905930","3026652197","3026652197","3167850324","3167850324","63159454","63159454"]}