{"id":1379,"date":"2016-10-10T09:00:30","date_gmt":"2016-10-10T07:00:30","guid":{"rendered":"http:\/\/vthink.fr\/en\/?p=1379"},"modified":"2016-10-09T20:36:27","modified_gmt":"2016-10-09T18:36:27","slug":"vro-retrieve-the-last-24h-events-from-vcenter","status":"publish","type":"post","link":"https:\/\/vthink.fr\/en\/2016\/10\/vro-retrieve-the-last-24h-events-from-vcenter\/","title":{"rendered":"[vRO] Retrieve the last 24h events from vCenter"},"content":{"rendered":"\n<!-- Quick Adsense WordPress Plugin: http:\/\/quickadsense.com\/ -->\n<div class=\"e93ad9a1ff002511692efbd236903a83\" data-index=\"1\" style=\"float: left; margin: 10px 10px 10px 0;\">\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<!-- ads1 -->\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:inline-block;width:300px;height:250px\"\r\n     data-ad-client=\"ca-pub-9785518987307332\"\r\n     data-ad-slot=\"8809267401\"><\/ins>\r\n<script>\r\n(adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\n<\/div>\n<p><img data-attachment-id=\"1387\" data-permalink=\"https:\/\/vthink.fr\/en\/2016\/09\/vro-comment-ajouter-une-base-de-donnees-sql-dans-vrealize-orchestrator\/vra-product-icon-mac_0-3\/#main\" data-orig-file=\"https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/vRA-Product-Icon-Mac_0-1.png?fit=256%2C256&amp;ssl=1\" data-orig-size=\"256,256\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"vra-product-icon-mac_0\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/vRA-Product-Icon-Mac_0-1.png?fit=256%2C256&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/vRA-Product-Icon-Mac_0-1.png?fit=256%2C256&amp;ssl=1\" loading=\"lazy\" class=\"size-full wp-image-1387 alignleft\" src=\"https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/vRA-Product-Icon-Mac_0-1.png?resize=142%2C142&#038;ssl=1\" alt=\"vra-product-icon-mac_0\" width=\"142\" height=\"142\" srcset=\"https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/vRA-Product-Icon-Mac_0-1.png?w=256&amp;ssl=1 256w, https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/vRA-Product-Icon-Mac_0-1.png?resize=126%2C126&amp;ssl=1 126w, https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/vRA-Product-Icon-Mac_0-1.png?resize=50%2C50&amp;ssl=1 50w\" sizes=\"(max-width: 142px) 100vw, 142px\" data-recalc-dims=\"1\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>How to retrieve the last 24h events from your vCenter with more than 999 events.<\/p>\n<p>As you know, by default the maximum number of events that you can retrieve from the vCenter is 999. I will show you how to display the last 24h of events in your vRealize Orchestrator Workflow.<\/p>\n<p><!--more--><\/p>\n<p>In this exemple i want to retrieve all the events in my vCenter since the last 24h.<\/p>\n<p>First, you need to add as an attribute the vCenter (Type :sdkconnection).<\/p>\n<p><img data-attachment-id=\"1449\" data-permalink=\"https:\/\/vthink.fr\/en\/2016\/10\/vro-recuperer-les-evenements-du-vcenter-des-24-dernieres-heures\/screen-shot-2016-10-09-at-19-43-57\/#main\" data-orig-file=\"https:\/\/i1.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-19.43.57.png?fit=1200%2C120&amp;ssl=1\" data-orig-size=\"1200,120\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sdk connection\" data-image-description=\"\" data-medium-file=\"https:\/\/i1.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-19.43.57.png?fit=300%2C30&amp;ssl=1\" data-large-file=\"https:\/\/i1.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-19.43.57.png?fit=700%2C70&amp;ssl=1\" loading=\"lazy\" class=\"aligncenter size-full wp-image-1449\" src=\"https:\/\/i1.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-19.43.57.png?resize=700%2C70&#038;ssl=1\" alt=\"sdk connection\" width=\"700\" height=\"70\" srcset=\"https:\/\/i1.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-19.43.57.png?w=1200&amp;ssl=1 1200w, https:\/\/i1.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-19.43.57.png?resize=300%2C30&amp;ssl=1 300w, https:\/\/i1.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-19.43.57.png?resize=768%2C77&amp;ssl=1 768w, https:\/\/i1.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-19.43.57.png?resize=1024%2C102&amp;ssl=1 1024w, https:\/\/i1.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-19.43.57.png?resize=220%2C22&amp;ssl=1 220w, https:\/\/i1.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-19.43.57.png?resize=460%2C46&amp;ssl=1 460w, https:\/\/i1.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-19.43.57.png?resize=50%2C5&amp;ssl=1 50w\" sizes=\"(max-width: 700px) 100vw, 700px\" data-recalc-dims=\"1\" \/><\/p>\n<p>Then you will initiliaze the events from the last 24h and create a collector. By default your collector will keep only 999 events.<\/p>\n<pre><code>System.debug(\"Initialize all the Events of the infrastructure minus 24 hours\");\r\n\/\/Initialize all the Events of the infrastructure minus 24 hours\r\nvar vcEventFilterSpec = new VcEventFilterSpec() ;\r\nvar vcEventFilterSpecByTime = new VcEventFilterSpecByTime() ;\r\nvar vcEventManager = sdk.eventManager;\r\nvar HostEvents = [];\r\n\r\nvar beginTime = new Date();\r\n\r\nbeginTime.setHours(beginTime.getHours()-24);\r\n\r\nvcEventFilterSpecByTime.beginTime = beginTime;\r\n\r\nSystem.debug(\"BeginTime : \"+beginTime);\r\n\r\nSystem.debug(\"Define Filter by time\");\r\nvcEventFilterSpec.time = vcEventFilterSpecByTime;\r\n\r\n\r\nvar collector = vcEventManager.createCollectorForEvents(vcEventFilterSpec);\r\n\r\n<\/code><\/pre>\n<p>Then what i want to do is to create a loop , and create a new collector while i have events to display.<\/p>\n<!-- Quick Adsense WordPress Plugin: http:\/\/quickadsense.com\/ -->\n<div class=\"e93ad9a1ff002511692efbd236903a83\" data-index=\"1\" style=\"float: left; margin: 10px 10px 10px 0;\">\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<!-- ads1 -->\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:inline-block;width:300px;height:250px\"\r\n     data-ad-client=\"ca-pub-9785518987307332\"\r\n     data-ad-slot=\"8809267401\"><\/ins>\r\n<script>\r\n(adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\n<\/div>\n\n<pre><code>\/\/Define Max task number per Collector (999 maximum)\r\nvar tasknumber = 999;\r\n\r\nvar tasks =[];\r\n\r\nvar collector = vcEventManager.createCollectorForEvents(vcEventFilterSpec);\r\n\r\nvar dummy = collector.rewindCollector();\r\n\r\nvar tasks = collector.readNextEvents(tasknumber);\r\n\r\nwhile (tasks.length == tasknumber) {\r\n    var last = tasks.length-1;\r\nSystem.debug(\"Number of event to analyze: \"+tasks.length);\r\nSystem.debug(\"First Event :\"+tasks[0].createdTime);\r\nSystem.debug(\"Last event :\"+tasks[last].createdTime);\r\n\r\nfor each (var task in tasks){\r\n    if(task.fullFormattedMessage != undefined ) {\r\n    System.debug(task.createdTime+\" \"+task.fullFormattedMessage);\r\n    }\r\n}\r\nvar tasks = collector.readNextEvents(tasknumber);\r\n}\r\n<\/code><\/pre>\n<p>Once the maximum number of events is lower than 999, i will create a simple loop and display the last events<\/p>\n<pre><code>\r\nvar last = tasks.length-1;\r\n\r\nSystem.debug(\"Number of event to analyze: \"+tasks.length);\r\nSystem.debug(\"First Event :\"+tasks[0].createdTime);\r\nSystem.debug(\"Last event :\"+tasks[last].createdTime);\r\n\r\nfor each (var task in tasks){\r\nif(task.fullFormattedMessage != undefined ) {\r\nSystem.debug(task.createdTime+\" \"+task.fullFormattedMessage);\r\n}\r\n}\r\n<\/code><\/pre>\n<p>And at the end, don&#8217;t forget to destroy your collectors.<\/p>\n<pre><code>collector.destroyCollector();<\/code><\/pre>\n<p>And now you will display all the event , line by line for the last 24h.<\/p>\n<p><img data-attachment-id=\"1448\" data-permalink=\"https:\/\/vthink.fr\/en\/2016\/10\/vro-recuperer-les-evenements-du-vcenter-des-24-dernieres-heures\/screen-shot-2016-10-09-at-20-00-24\/#main\" data-orig-file=\"https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-20.00.24.png?fit=1200%2C722&amp;ssl=1\" data-orig-size=\"1200,722\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"screen-shot-2016-10-09-at-20-00-24\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-20.00.24.png?fit=300%2C181&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-20.00.24.png?fit=700%2C421&amp;ssl=1\" loading=\"lazy\" class=\"aligncenter size-full wp-image-1448\" src=\"https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-20.00.24.png?resize=700%2C421&#038;ssl=1\" alt=\"screen-shot-2016-10-09-at-20-00-24\" width=\"700\" height=\"421\" srcset=\"https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-20.00.24.png?w=1200&amp;ssl=1 1200w, https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-20.00.24.png?resize=300%2C181&amp;ssl=1 300w, https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-20.00.24.png?resize=768%2C462&amp;ssl=1 768w, https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-20.00.24.png?resize=1024%2C616&amp;ssl=1 1024w, https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-20.00.24.png?resize=209%2C126&amp;ssl=1 209w, https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-20.00.24.png?resize=432%2C260&amp;ssl=1 432w, https:\/\/i0.wp.com\/vthink.fr\/wp-content\/uploads\/Screen-Shot-2016-10-09-at-20.00.24.png?resize=50%2C30&amp;ssl=1 50w\" sizes=\"(max-width: 700px) 100vw, 700px\" data-recalc-dims=\"1\" \/><\/p>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div><!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; &nbsp; &nbsp; How to retrieve the last 24h events from your vCenter with more than 999 events. As you know, by default the maximum number of events that you can retrieve from the vCenter is 999. I will show you how to display the last 24h of events in your vRealize Orchestrator Workflow.<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":2,"featured_media":1292,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1807],"tags":[1798,1797,1801,1806,1794,1763,1802,1800,1123,1043,1079,1705,1803,1102,1838,1105,1796,1804,1839,1795,1840,1837,1799,1841,1278,1805,1067,1644,1842,1843,1087,1714,1662,1121,1081,1720],"_links":{"self":[{"href":"https:\/\/vthink.fr\/en\/wp-json\/wp\/v2\/posts\/1379"}],"collection":[{"href":"https:\/\/vthink.fr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vthink.fr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vthink.fr\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/vthink.fr\/en\/wp-json\/wp\/v2\/comments?post=1379"}],"version-history":[{"count":7,"href":"https:\/\/vthink.fr\/en\/wp-json\/wp\/v2\/posts\/1379\/revisions"}],"predecessor-version":[{"id":1458,"href":"https:\/\/vthink.fr\/en\/wp-json\/wp\/v2\/posts\/1379\/revisions\/1458"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vthink.fr\/en\/wp-json\/wp\/v2\/media\/1292"}],"wp:attachment":[{"href":"https:\/\/vthink.fr\/en\/wp-json\/wp\/v2\/media?parent=1379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vthink.fr\/en\/wp-json\/wp\/v2\/categories?post=1379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vthink.fr\/en\/wp-json\/wp\/v2\/tags?post=1379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}