{"id":1980,"date":"2010-12-12T02:51:24","date_gmt":"2010-12-12T01:51:24","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=1980"},"modified":"2010-12-12T02:51:24","modified_gmt":"2010-12-12T01:51:24","slug":"state-based-on-logon-status","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=1980","title":{"rendered":"State based on logon status"},"content":{"rendered":"<p>I read a question this week about presenting a state based on if a service account was logged on to a machine or not. There are a couple of different ways to do that. We will need a monitor in both of them, as we want to present a state. You could solve it with a monitor running a script, checking current logged on users. You could also solve it with a monitor checking log-on and log-out events.<\/p>\n<p>If you want to do it with two events and running server 2008 you could look at even 4624 (an account was successfully logged on) and 4647 (User initiated log-off). To configure a monitor like that you follow the steps below. This example will configure a monitor to generate an alert if not the CONTOSO\\svc-contoso-service account is logged on.<\/p>\n<ol>\n<li>In the console, navigate to Authoring\/Management Pack Objects<\/li>\n<li>Right-click monitors and create a new Simple Event Detection\/Windows Event Reset monitor<\/li>\n<li>Choose a suitable management pack, not the default management pack. Click Next<\/li>\n<li>Input a name, a target and choose a parent monitor. Click Next<\/li>\n<li>Event Log (Unhealthy Event). Select Security as event log name. Click Next<\/li>\n<li>Event Expression (Unhealthy Event). Select Event ID equals 4647 and EventDescription Contains CONTOSO\\svc-contoso-service. Click Next<br \/>\n<a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1983\" title=\"AccountCheck01\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck01-300x131.jpg\" alt=\"\" width=\"300\" height=\"131\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck01-300x131.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck01.jpg 544w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/li>\n<li>Event Log (Healthy Event). Select Security as event log name. Click Next<\/li>\n<li>Event Expression (Healthy Event). Select Event ID equals 4624 and EventDescription Contains CONTOSO\\svc-contoso-service. Click Next<\/li>\n<li>Configure Health. Click Next<\/li>\n<li>Configure Alert. Check the &#8220;Generate alerts for this monitor&#8221; check box. Click Create<\/li>\n<p>By default this new monitor will be forced to healthy state first. This mean we will not get an alert until the account log off. In other words, if there is a\u00c2\u00a0machine where this account is not logged on right now, Operations Manager will not notice it. It is only looking for the log-in and log-off event. To generate an alert we first need to log-on with the account, in this example CONTOSO\\svc-contoso-service, then log-out again. The monitor will then go into unhealthy state.<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1986\" title=\"AccountCheck02\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck02-300x199.jpg\" alt=\"\" width=\"300\" height=\"199\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck02-300x199.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck02.jpg 506w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck03.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1990\" title=\"AccountCheck03\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck03-300x177.jpg\" alt=\"\" width=\"300\" height=\"177\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck03-300x177.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck03.jpg 529w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The second way to solve this is with a script. To configure a monitor like that you follow the steps below<\/ol>\n<ol>\n<li>In the console, navigate to Authoring\/Management Pack Objects<\/li>\n<li>Right-click monitors and create a new Scripting\/Generic\/Timed Script Two State Monitor<\/li>\n<li>Choose a suitable management pack, not the default management pack. Click Next<\/li>\n<li>Input a name, a target and choose a parent monitor. Click Next<\/li>\n<li>Schedule. Configure how often you want the script to run, to see if the account is logged on. Dont configure it to run to often, check your organization requirements. Click Next<\/li>\n<li>Script. Input a script name, for example accountcheck.vbs. Paste the script into the script text field. You can download the script <a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/checkaccount.txt\">here<\/a>. One of the first lines in the script configure which account to check. Don&#8217;t forget to update it. Click Next<\/li>\n<li>Unhealthy Expression. Input<br \/>\nProperty[@Name=&#8217;Status&#8217;] Does not equal OK<br \/>\nClick Next<\/li>\n<li>Healthy Expression. Input<br \/>\nProperty[@Name=&#8217;Status&#8217;] Equals OK<br \/>\nClick Next<\/li>\n<li>Health. Click Next<\/li>\n<li>Configure Alert. Check the &#8220;Generate alerts for this monitor&#8221; check-box and input a alert description. Click Create<\/li>\n<\/ol>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck04.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1995\" title=\"AccountCheck04\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck04-300x139.jpg\" alt=\"\" width=\"300\" height=\"139\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck04-300x139.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck04.jpg 541w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>If you need to display the account status in a distributed application it is easiest if you can target the monitor to a new customer class.\u00c2\u00a0The health model of the class will then be only this\u00c2\u00a0monitor, in other words the class instance health\u00c2\u00a0it will only show the status of the account. \u00c2\u00a0<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck05.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1998\" title=\"AccountCheck05\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck05-300x164.jpg\" alt=\"\" width=\"300\" height=\"164\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck05-300x164.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/12\/AccountCheck05.jpg 806w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Thanks to Guy Thomas for his script that I\u00c2\u00a0adapted.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I read a question this week about presenting a state based on if a service account was logged on to a machine or not. There are a couple of different ways to do that. We will need a monitor in both of them, as we want to present a state. You could solve it with &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=1980\">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,"footnotes":""},"categories":[19],"tags":[],"class_list":["post-1980","post","type-post","status-publish","format-standard","hentry","category-operations-manager-2007"],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1980","targetHints":{"allow":["GET"]}}],"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=1980"}],"version-history":[{"count":15,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1980\/revisions"}],"predecessor-version":[{"id":2001,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1980\/revisions\/2001"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1980"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}