{"id":3870,"date":"2014-01-09T13:04:57","date_gmt":"2014-01-09T12:04:57","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=3870"},"modified":"2014-01-09T13:08:12","modified_gmt":"2014-01-09T12:08:12","slug":"logging-in-service-management-automation-sma","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=3870","title":{"rendered":"Logging in Service Management Automation (SMA)"},"content":{"rendered":"<p>In Service Management Automation (SMA) there are a couple of different ways to write to a log. In this blog post I will show you how to write to the job history tab and how to write to an external SQL database.<\/p>\n<p>If you have published a runbook you can use Write-Verbose, Write-Progress and Write-Debug as shown in figure 1 to write log message. The result of write actions will be shown in History for each runbook job, example shown in figure 2. Figure 3 show important settings to make this work, you need to enable logging on the runbook, else you will see no log messages in the job history.<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe1.png\"><img decoding=\"async\" loading=\"lazy\" alt=\"\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe1.png\" width=\"523\" height=\"327\" \/><\/a><\/p>\n<p><span style=\"color: #44546a; font-size: 9pt;\"><em>Figure 1 Write to log examples<br \/>\n<\/em><\/span><\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe2.png\"><img decoding=\"async\" loading=\"lazy\" alt=\"\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe2.png\" width=\"732\" height=\"376\" \/><\/a><\/p>\n<p><span style=\"color: #44546a; font-size: 9pt;\"><em>Figure 2 Log examples<br \/>\n<\/em><\/span><\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe3.png\"><img decoding=\"async\" loading=\"lazy\" alt=\"\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe3.png\" width=\"711\" height=\"861\" \/><\/a><\/p>\n<p><span style=\"color: #44546a; font-size: 9pt;\"><em>Figure 3 Log settings<br \/>\n<\/em><\/span><\/p>\n<p>Another alternative for logging is logging to an external database. We have earlier used the same <a href=\"http:\/\/contoso.se\/blog\/?p=3681\">logging solution for Orchestrator runbooks<\/a>. Figure 4 shows a SMA runbook that writes to a SQL database named SMALOG. As you can see in figure 4 the &#8220;writelog&#8221; SMA runbook use three parameters, Runbook, Job and Description. Other runbooks invoking this runbook need to provide current runbook, current job ID and a log message description. To get the current runbook name and job ID you can use the code shown in figure 5. The writelog runbook use the Get-Date to get current time. The log database is shown in figure 6.<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe4.png\"><img decoding=\"async\" loading=\"lazy\" alt=\"\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe4.png\" width=\"914\" height=\"683\" \/><\/a><\/p>\n<p><span style=\"color: #44546a; font-size: 9pt;\"><em>Figure 4 SMA runbook writes logs to SQL database<br \/>\n<\/em><\/span><\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe5.png\"><img decoding=\"async\" loading=\"lazy\" alt=\"\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe5.png\" width=\"628\" height=\"179\" \/><\/a><\/p>\n<p><span style=\"color: #44546a; font-size: 9pt;\"><em>Figure 5 Get current runbook name and job ID<br \/>\n<\/em><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe6.png\"><img decoding=\"async\" loading=\"lazy\" alt=\"\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/010914_1204_LogginginSe6.png\" width=\"1138\" height=\"329\" \/><\/a><\/p>\n<p><span style=\"color: #44546a; font-size: 9pt;\"><em>Figure 6 Example of log database<br \/>\n<\/em><\/span><\/p>\n<p>Download examples here. <a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2014\/01\/Logging.zip\">Logging<\/a>\u00c2\u00a0. Note that this is provided &#8220;AS-IS&#8221; with no warranties at all. This is not a production ready solution, just an idea and an example.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Service Management Automation (SMA) there are a couple of different ways to write to a log. In this blog post I will show you how to write to the job history tab and how to write to an external SQL database. If you have published a runbook you can use Write-Verbose, Write-Progress and Write-Debug &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=3870\">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":[62],"tags":[],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3870"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3870"}],"version-history":[{"count":2,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3870\/revisions"}],"predecessor-version":[{"id":3873,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3870\/revisions\/3873"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3870"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}