{"id":2066,"date":"2024-10-17T14:35:13","date_gmt":"2024-10-17T18:35:13","guid":{"rendered":"https:\/\/enterpriseadmins.org\/blog\/?p=2066"},"modified":"2024-10-17T14:35:13","modified_gmt":"2024-10-17T18:35:13","slug":"automating-cluster-management-with-aria-operations-api","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/automating-cluster-management-with-aria-operations-api\/","title":{"rendered":"Automating Cluster Management with Aria Operations API"},"content":{"rendered":"\n<p>As part of routine maintenance, it is sometimes necessary to take an Aria Operations cluster offline.  For example, it is recommended to take the cluster offline to perform backups (<a href=\"https:\/\/docs.vmware.com\/en\/VMware-Aria-Operations\/8.12\/Best-Practices-Operations\/GUID-1D058B4A-93BA-44D1-8794-AE8E1B96B3E4.html\">https:\/\/docs.vmware.com\/en\/VMware-Aria-Operations\/8.12\/Best-Practices-Operations\/GUID-1D058B4A-93BA-44D1-8794-AE8E1B96B3E4.html<\/a>).<\/p>\n\n\n\n<p>Since most folks want to schedule backups, it is important to be able to leverage automation to take the cluster offline. There is an cluster management API document at <a href=\"https:\/\/ops.example.com\/casa\/api-guide.html\">https:\/\/ops.example.com\/casa\/api-guide.html<\/a> that has some details on how to do this.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Authentication<\/h2>\n\n\n\n<p>When logging into this API, I provided the admin username\/password combination. Here is an example of checking the cluster state using that method:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$creds = Get-Credential\n(Invoke-RestMethod -URI https:\/\/ops.example.com\/casa\/sysadmin\/cluster\/online_state -Credential $creds).cluster_online_state_snapshot<\/code><\/pre>\n\n\n\n<p>However, I&#8217;d prefer to use a centrally managed service account in Active Directory for such tasks. The ability to do this was first introduced in vRealize Operations 8.6 (<a href=\"https:\/\/docs.vmware.com\/en\/vRealize-Operations\/8.6\/com.vmware.vcom.config.doc\/GUID-5B5BC860-128C-4A87-9BEA-2711FB68412C.html\">doc<\/a>) and still exists in Aria Operations 8.18 (<a href=\"https:\/\/docs.vmware.com\/en\/VMware-Aria-Operations\/8.18\/Configuring-Operations\/GUID-5B5BC860-128C-4A87-9BEA-2711FB68412C.html\">doc<\/a>). It depends on a separate Active Directory configuration \/ definition than the one in the product UI. The links provided show where\/how to configure this identity provider from the <code>\/admin<\/code> interface.  Here is a screenshot showing this configuration:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"678\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-1024x678.png\" alt=\"\" class=\"wp-image-2073\" srcset=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-1024x678.png 1024w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-300x199.png 300w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-768x508.png 768w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image.png 1038w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Once Active Directory is configured for admin operations, we need to change our API authentication slightly to be able to use it. In the original example, we provided our username &amp; password as a powershell credential object. In this example, we&#8217;ll end up with an extra API call to authenticate, then use the resulting bearer token as a header when checking the status. A code sample is below, but you&#8217;ll notice the authorization header that passes <code>vrops-ldap<\/code> along with base64 encoded username (as an AD userPrincipalName), colon, and password to an <code>authorize<\/code> resource. That resource will return a token that we&#8217;ll provide as a header to check the cluster status.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$b64 = &#91;System.Convert]::ToBase64String(&#91;System.Text.encoding]::ASCII.GetBytes(\"h267-opsbu@lab.enterpriseadmins.org:VMware1!\"))\n\n$authorize = Invoke-RestMethod -Uri 'https:\/\/ops.example.com\/casa\/authorize' -Method Post -ContentType 'application\/json' -Headers @{Authorization=\"vrops-ldap $b64\"; Accept='application\/json'}\n\n(Invoke-RestMethod -URI https:\/\/ops.example.com\/casa\/sysadmin\/cluster\/online_state -Headers @{Authorization=\"Bearer $($authorize.accessToken)\"; Accept='application\/json'} -ContentType 'application\/json').cluster_online_state_snapshot<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Taking the cluster offline<\/h2>\n\n\n\n<p>With the authentication sorted out above, we can now post to this API to take the cluster offline.  You&#8217;ll notice that we set the state to offline and provide a reason why.  The example uses the same bearer token that we created in the above example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$body = @{ 'online_state'='OFFLINE'; 'online_state_reason'='Lets back this thing up.'} | convertto-json\nInvoke-RestMethod -URI https:\/\/ops.example.com\/casa\/sysadmin\/cluster\/online_state -Body $body -Method POST -ContentType 'application\/json'  -Headers @{Authorization=\"Bearer $($authorize.accessToken)\"; Accept='application\/json'}<\/code><\/pre>\n\n\n\n<p>The above example submits a request to take the cluster offline but returns immediately after doing so.  In the URI we could provide a <code>?async=false<\/code> so that our command waits until completion.  Another option would be to submit an async request (default), then create a loop to periodically check the cluster state using the prior &#8216;get&#8217; request until the cluster is offline.  I prefer the periodic polling option, as you can code in your own counter\/timing\/failure logic as needed.<\/p>\n\n\n\n<p>If you check out the docs at \/casa\/api-guide.html, you&#8217;ll also see examples of setting the &#8220;Show reason on maintenance page&#8221; checkbox via the JSON body.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bring the cluster back online<\/h2>\n\n\n\n<p>After our maintenance \/ backup task is complete, we&#8217;ll want to bring the cluster back online.  In this example we don&#8217;t need to provide a reason in our body.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$body = @{ 'online_state'='ONLINE'} | convertto-json\nInvoke-RestMethod -URI https:\/\/ops.example.com\/casa\/sysadmin\/cluster\/online_state?async=false -Body $body -Method POST -ContentType 'application\/json' -Headers @{Authorization=\"Bearer $($authorize.accessToken)\"; Accept='application\/json'}<\/code><\/pre>\n\n\n\n<p>In this example I&#8217;m using the <code>?async=false<\/code> so that the API call doesn&#8217;t return until the cluster is back online.  Again, we could opt to use the default async request and periodically poll the service if we&#8217;d like.  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The <code>casa<\/code> API is very useful for automating cluster management tasks.  This article focuses on a few examples related to cluster state changes and authentication, but the API supports many other things, like PAK file uploads, NTP &amp; certificate management, and even the configuration of AD authentication.  You should check out \/casa\/api-guide.html on an Aria Operations node for more examples. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>As part of routine maintenance, it is sometimes necessary to take an Aria Operations cluster offline. For example, it is recommended to take the cluster offline to perform backups (https:\/\/docs.vmware.com\/en\/VMware-Aria-Operations\/8.12\/Best-Practices-Operations\/GUID-1D058B4A-93BA-44D1-8794-AE8E1B96B3E4.html). Since most folks want to schedule backups, it is important &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/automating-cluster-management-with-aria-operations-api\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"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":[9,3,4],"tags":[],"class_list":["post-2066","post","type-post","status-publish","format-standard","hentry","category-lab-infrastructure","category-scripting","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=2066"}],"version-history":[{"count":5,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2066\/revisions"}],"predecessor-version":[{"id":2075,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2066\/revisions\/2075"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=2066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=2066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=2066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}