{"componentChunkName":"component---src-templates-default-template-tsx","path":"/tutorials/tutorial-first-incident-connector/","result":{"data":{"asciidoc":{"id":"33bb1e14-ed88-547e-b660-15593e26e189","html":"<div class=\"sect1\">\n<h2 id=\"_first_incident_connector\">First incident connector</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>The <code>Domain Object Api</code> expects messages in <a href=\"https://github.com/arago/OGIT/tree/master/SDF\">sdf</a> format. The sdf format is defined in views, e.g. the sdf for an <a href=\"https://github.com/arago/OGIT/blob/master/SDF/Automation/incident.json\">incident</a> is defined.</p>\n</div>\n<div class=\"sect2\">\n<h3 id=\"_creating_the_model\">Creating the model</h3>\n<div class=\"paragraph\">\n<p>Before we can start sending incidents to HIRO we need to have a <code>model</code> or representation of the <code>environment</code> which we want to automate in the system.\nThe smallest possible model is a single Node. Such a default node can be created by the Domain Object Api with</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-bash\" data-lang=\"bash\">curl -kH 'Content-type:application/json' -X PUT 'https://doapi.almato.ai/views/default/objects/defaultMachineId' -d '{\"$type\":\"configMachine\",\"name\":\"defaultMachine\",\"systemType\":\"Virtual\"}'</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>The SDF message in the call to define the default node looks like:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">{\n  \"$type\": \"configMachine\",\n  \"name\": \"defaultMachine\",\n  \"systemType\":\"Virtual\"\n}</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>In the following calls the <code>defaultMachineId</code> can be used to define the starting point  in the <code>model</code> for newly created <code>Automation Issues</code>. An <code>Automation Issue</code> represent any kind of <code>automation task</code>. In the following we will take incident as an example.</p>\n</div>\n</div>\n<div class=\"sect2\">\n<h3 id=\"_creating_an_incident\">Creating an Incident</h3>\n<div class=\"paragraph\">\n<p>To create an Automation Issue which represents an incident the following call can be made to the Domain Object Api:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-bash\" data-lang=\"bash\">curl -kH 'Content-type:application/json' -X PUT 'https://doapi.almato.ai/views/default/objects/inc-0001' -d' {\"$type\":\"incident\",\"subject\":\"My first incident\",\"originNode\":\"defaultMachineId\",\"summary\":\"This is the first incident created by me\",\"priority\":\"important\",\"description\":\"The incident was created for testing.\",\"urgency\":\"high\",\"sourceStatus\":\"open\"}'</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>The SDF message in this call is</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">{\n  \"$type\": \"incident\",\n  \"subject\": \"My first incident\",\n  \"originNode\": \"defaultMachineId\",\n  \"summary\": \"This is the first incident created by me\",\n  \"priority\": \"important\",\n  \"description\": \"The incident was created for testing.\",\n  \"urgency\": \"high\",\n  \"sourceStatus\": \"open\"\n}</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>In HIRO the following AutomationIssue will be created:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">{\n  \"/ProcessIssue\": \"process me\",\n  \"/actual_type\": \"IncidentType\",\n  \"/description\": \"The incident was created for testing.\",\n  \"/priority\": \"important\",\n  \"/sourceStatus\": \"open\",\n  \"/summary\": \"This is the first incident created by me\",\n  \"/urgency\": \"high\",\n  \"ogit/Automation/originNode\": \"defaultMachineId\",\n  \"ogit/_graphtype\": \"vertex\",\n  \"ogit/_id\": \"cjqzbn759dxq27f58egrs3ped\",\n  \"ogit/_type\": \"ogit/Automation/AutomationIssue\",\n  \"ogit/_xid\": \"prefix:inc-0001\",\n  \"ogit/status\": \"PROCESSING\",\n  \"ogit/subject\": \"My first incident\"\n}</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>The issue will be processed by HIRO. Different knowledge Items <code>kis</code> will be applied to solve the task at hand.</p>\n</div>\n<div class=\"paragraph\">\n<p>If the <a href=\"https://github.com/arago/OGIT/blob/master/SDF/Automation/incident.json\">incident sdf</a> does not contain required attributes, either new attributes can be requested on <a href=\"https://github.com/arago/OGIT\">OGIT</a>, or free attribute (starting with <code>/</code>) can be sent to the Domain Object Api.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">{\n  \"$type\": \"incident\",\n  \"subject\": \"My first incident\",\n  \"originNode\": \"defaultMachineId\",\n  \"summary\": \"This is the first incident created by me\",\n  \"description\": \"The incident was created for testing.\",\n  \"/test\": \"this is a free test variable\"\n}</code></pre>\n</div>\n</div>\n</div>\n<div class=\"sect2\">\n<h3 id=\"_check_message_was_successful\">Check message was successful</h3>\n<div class=\"paragraph\">\n<p>The Domain Object Api has non-blocking calls. So the execution of a call to create or update an incident (and any other type of sdf) will return a message with a transaction link.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">{\n  \"link\": \"/views/default/transactions/0c6fc0cd-d6c9-4ad0-a965-859e6a3771bd\",\n  \"object\": \"/views/default/objects/inc-0001\",\n  \"status\": \"waiting\",\n  \"requestedAt\": 1616745367187,\n  \"updatedAt\": 1616745367187,\n  \"startedAt\": -1,\n  \"errors\": []\n}</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>The transactions can be checked by the link or by</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-bash\" data-lang=\"bash\">curl https://doapi.almato.ai/views/default/transactions</code></pre>\n</div>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">  {\n    \"link\": \"/views/default/transactions/0c6fc0cd-d6c9-4ad0-a965-859e6a3771bd\",\n    \"object\": \"/views/default/objects/inc-0001\",\n    \"status\": \"done-success\",\n    \"requestedAt\": 1616745367187,\n    \"updatedAt\": 1616745369450,\n    \"startedAt\": 1616745369335,\n    \"errors\": []\n  }</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>If the transactions was done successfully the status of the transaction will show <code>done-success</code>. More details can be found in\n<a href=\"https://github.com/arago/hiro-documentation/blob/master/dev-portal/7.0/content/documentation/integration/DomainObjectApi/RestCalls/CheckTransaction.adoc\">transactions</a> documentation.</p>\n</div>\n<div class=\"paragraph\">\n<p>It is also possible to <a href=\"https://github.com/arago/hiro-documentation/blob/master/dev-portal/7.0/content/documentation/integration/DomainObjectApi/RESTOperations.adoc#subscribe-to-notifications\">subscribe</a> to the transactions via websocket with <code>transaction.done-success</code> and <code>transaction.done-failure</code> respectively.</p>\n</div>\n</div>\n<div class=\"sect2\">\n<h3 id=\"_getting_updates\">Getting updates</h3>\n<div class=\"paragraph\">\n<p>Once HIRO starts working on the Automation Issue, every step will be documented. Every step will be exposed as an <a href=\"https://github.com/arago/hiro-documentation/blob/master/dev-portal/7.0/content/documentation/integration/DomainObjectApi/CheckUpdates.adoc\"> update</a> message by the Domain Object Api.</p>\n</div>\n<div class=\"paragraph\">\n<p>To check the updates, following call can be done with <code>offset</code> or <code>iterator</code> as a parameter.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-bash\" data-lang=\"bash\">curl https://doapi.almato.ai/views/default/updates?offset=0</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>The updates have the following format:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">[\n  {\n    \"link\": \"/views/default/updates/0\",\n    \"offset\": 0,\n    \"object\": {\n      \"summary\": \"The summary has been updated by HIRO\",\n      \"hiroStatus\": \"PROCESSING\",\n      \"$delta\": [\n        \"summary\"\n      ],\n      \"comments\": {\n        \"inc-0001-COMMENT\": {\n          \"$delta\": [],\n          \"comments\": []\n        }\n      },\n      \"$type\": \"incident\",\n      \"$id\": \"inc-0001\"\n    }\n  }\n]</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>In <code>$id</code> the id of the incident for which the update is sent is shown.\nIn <code>$delta</code> the fields are shown which have changed by HIRO.\nThe <code>comments</code> section shows the steps done by HIRO.</p>\n</div>\n<div class=\"paragraph\">\n<p>It is also possible to <a href=\"https://github.com/arago/hiro-documentation/blob/master/dev-portal/7.0/content/documentation/integration/DomainObjectApi/RESTOperations.adoc#subscribe-to-notifications\">subscribe</a> to the updates via websocket with <code>update.received</code>.</p>\n</div>\n</div>\n<div class=\"sect2\">\n<h3 id=\"_interactive_communicating_with_hiro\">Interactive communicating with HIRO</h3>\n<div class=\"paragraph\">\n<p>Comment or work notes can be sent to the Domain Object API, on creation or while the incident is being processed by HIRO. If an incident is created like described in <code>Creating an Incident</code> an additional comment can be added. For example a comment can be sent to stop processing:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-bash\" data-lang=\"bash\">curl -kH 'Content-type:application/json' -X PUT 'https://doapi.almato.ai/views/default/objects/inc-0001' -d '{ \"$type\": \"incident\", \"comments\": { \"inc-0001-COMMENT\": { \"comments\": [{ \"timestamp\": 1584632631000, \"value\": \"[HIRO] Please eject\" }] } } }'</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>The SDF message in this call is:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">{\n  \"$type\": \"incident\",\n  \"comments\": {\n    \"inc-0001-COMMENT\": {\n      \"comments\": [\n        {\n          \"timestamp\": 1584632631000,\n          \"value\": \"[HIRO] Please eject\"\n        }\n      ]\n    }\n  }\n}</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>Now this is added to the <code>/comments</code> attribute in the Automation Issue. Additionally, it is stored in a timeseries vertex with the name <code>UserComment</code>.\nA ki can react on this comment. HIRO will eject the Automation Issue, if the following ki is deployed:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre>ki\n  title: \"Eject issue on request\"\n  description: \"Eject issue on request\"\non\n  ogit/_id\nwhen\n  comments =~ \"[HIRO].*eject\"\n  ProcessIssue\ndo\n  eject_issue(\"Issue has been ejected on request\")</pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>This will result in a changed processing status of the Automation Issue. This is reflected in an update exposed on the Domain Object Api&#8217;s update endpoint:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\"> {\n    \"link\": \"/views/default/updates/1\",\n    \"offset\": 1,\n    \"object\": {\n      \"summary\": \"The summary has been updated by HIRO\",\n      \"hiroStatus\": \"TERMINATED\",\n      \"$delta\": [\n        \"hiroStatus\"\n      ],\n\n      \"$type\": \"incident\",\n      \"$id\": \"inc-0001\"\n    }\n  }</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>Depending on the kis available in HIRO different reactions can follow a comment in the incident.</p>\n</div>\n</div>\n</div>\n</div>","document":{"main":"First incident connector","title":"First incident connector","subtitle":""},"fields":{"toc":false,"location":["tutorials","tutorial-first-incident-connector"]}},"sidebarYaml":{"id":"0acf6fc1-95eb-5854-8f81-d5561b07a582","showIndex":null}},"pageContext":{"id":"33bb1e14-ed88-547e-b660-15593e26e189","parent":"tutorials"}},"staticQueryHashes":["1010459453","1010459453","2356112386","2356112386","2603905930","2603905930","3026652197","3026652197","3167850324","3167850324","63159454","63159454"]}