{"id":3772,"date":"2013-10-09T11:35:56","date_gmt":"2013-10-09T09:35:56","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=3772"},"modified":"2013-10-09T11:35:56","modified_gmt":"2013-10-09T09:35:56","slug":"build-your-own-write-to-log-activity","status":"publish","type":"post","link":"https:\/\/contoso.se\/blog\/?p=3772","title":{"rendered":"Build your own write to log activity"},"content":{"rendered":"<p>In a number of blog posts I have been writing about how to create a log for your runbooks. The solution I like the most is to write to a SQL database. Even if you do that there is always a small risk that some colleagues don\u00e2\u20ac\u2122t write the log in the same way. For example someone use 1-2-3 instead of low-medium-high when writing severity. One way to handle that is data validation in your log runbook. Another way is to create a new activity where colleagues can pick from menus.<\/p>\n<p>First thing you need to build a &#8220;write to log&#8221; activity is a Powershell script that do the &#8220;write to database&#8221; part.<\/p>\n<p><code><br \/>\nparam($Argument1,$Argument2,$Argument3)<br \/>\n$DESCRIPTION = $Argument3<br \/>\n$DESCRIPTION = $description.replace(\"'\",\"''\")<br \/>\n$DATE = get-date -format s<br \/>\n$RUNBOOK = $Argument1<br \/>\n$SEVERITY = $Argument2<br \/>\n$conn = New-Object System.Data.SqlClient.SqlConnection<br \/>\n$conn.ConnectionString = \"Data Source=SCO12SP1-01;Initial Catalog=OrchestratorTool;Integrated Security=SSPI;\"<br \/>\n$conn.open()<br \/>\n$cmd = New-Object System.Data.SqlClient.SqlCommand<br \/>\n$cmd.connection = $conn<br \/>\n$cmd.CommandText = \"INSERT INTO Log (DATE,RUNBOOK,SEVERITY,DESCRIPTION)<br \/>\nVALUES ('$DATE','$RUNBOOK','$SEVERITY','$DESCRIPTION')\"<br \/>\n$cmd.executenonquery()<br \/>\n$conn.close()<br \/>\n<\/code><\/p>\n<p>As you can see the SQL server name (SCO12SP1-01) and the SQL database name (OrchestratorTool) is hardcoded into the script. This is because that will not change, when using this activity we will always write to the same log database. Once the script is ready we can use the <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=28725\">Orchestrator Integration Toolkit<\/a> to build an activity and an integration pack. When configure the activity, configure it to run the Powershell script and pass the arguments.<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct01.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-3775\" alt=\"20131009_WriteLogAct01\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct01-300x236.jpg\" width=\"300\" height=\"236\" srcset=\"https:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct01-300x236.jpg 300w, https:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct01.jpg 606w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>When building the integration pack make sure to attach the PowerShell script. The Powershell script will be deployed together with the integration pack to all your runbook servers. Note that the Severity parameter is configured as Selection. It is configured as a drop down menu where users can pick severity from a list.<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct02.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-3776\" alt=\"20131009_WriteLogAct02\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct02-300x233.jpg\" width=\"300\" height=\"233\" srcset=\"https:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct02-300x233.jpg 300w, https:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct02.jpg 626w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>When using the activity you can pick severity from a menu. Runbook Name is published by all activities by default.<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct03.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-3777\" alt=\"20131009_WriteLogAct03\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct03-300x242.jpg\" width=\"300\" height=\"242\" srcset=\"https:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct03-300x242.jpg 300w, https:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/20131009_WriteLogAct03.jpg 778w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>You can download the integration pack and example files here, <a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2013\/10\/NOT-SUPPORTED.zip\">NOT SUPPORTED<\/a>. Note that this is provided \u00e2\u20ac\u0153AS-IS\u00e2\u20ac\u009d with no warranties at all. This is not a production ready solution, just an idea and an example.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a number of blog posts I have been writing about how to create a log for your runbooks. The solution I like the most is to write to a SQL database. Even if you do that there is always a small risk that some colleagues don\u00e2\u20ac\u2122t write the log in the same way. For &hellip; <a href=\"https:\/\/contoso.se\/blog\/?p=3772\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[60],"tags":[],"_links":{"self":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3772"}],"collection":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3772"}],"version-history":[{"count":4,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3772\/revisions"}],"predecessor-version":[{"id":3780,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3772\/revisions\/3780"}],"wp:attachment":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}