9 Replies Latest reply on Oct 9, 2019 7:16 AM by LucD

    Script to report RPO violations

    Baoth Novice

      Hi all

       

      I have seen a few forums posts in regards to something similar to what I am trying to achieve, and although I understand getting replication status is somewhat difficult as there is no public API, I am hoping that something can be tweaked to get what I need via a script.

       

      I am currently running the below which I found here:

       

      Get-VIEvent -MaxSamples ([int]::MaxValue) | Where { $_.EventTypeId -match "hbr|rpo" } | Select CreatedTime, FullFormattedMessage, @{Name="VMName";Expression={$_.Vm.Name}} | export-csv -NoTypeInformation -Path ([Environment]::GetFolderPath("Desktop") + "\HBR-RPOEvents.csv")

       

      However, that is returning everything under the FullFormattedMessage column. I'd like to filter that so it only contains "Virtual machine vSphere Replication RPO is violated by 1 minute(s)".

       

      If possible, I would like to avoid the 1 minute part of the log though. The reason for this is that Alerts work well enough, and will email me when something is violated, but its constantly sending me the 1 minute messages, which subsequently clear under normal operation.

       

      I'd ultimately like to get to a stage where I'm alerted if something is violated by more than 1 minute, and covers the last 24 hours.

       

      Hope you can help.

       

      Thanks.

        • 1. Re: Script to report RPO violations
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          On the 1st part of your question, you can extend your Where-clause to filter on the message content.

          Something like this

           

          Get-VIEvent -MaxSamples ([int]::MaxValue) |

          Where { $_.EventTypeId -match "hbr|rpo" -and $_.FullFormattedMessage -match "Virtual machine vSphere Replication RPO is violated by 1 minute(s)" } |

          Select CreatedTime, FullFormattedMessage,

              @{Name="VMName";Expression={$_.Vm.Name}} |

          Export-Csv -NoTypeInformation -Path ([Environment]::GetFolderPath("Desktop") + "\HBR-RPOEvents.csv")

          • 2. Re: Script to report RPO violations
            Baoth Novice

            Thanks LucD

             

            I have it a go, and it didn't return anything after a good few minutes.

             

            Tried this section of the script, and nothing is returned in the PS window:

             

            Get-VIEvent -Start (Get-Date).adddays(-2) -MaxSamples ([int]::MaxValue) |

            Where { $_.EventTypeId -match "hbr|rpo" -and $_.FullFormattedMessage -match "Virtual machine vSphere Replication RPO is violated by 1 minute(s)" }

             

            If I drop the 2nd match section, I get data returned successfully.

            • 3. Re: Script to report RPO violations
              LucD Guru
              User ModeratorsCommunity WarriorsvExpert

              Could you provide a sample of the text in the FullFormattedMessage you want?

              • 4. Re: Script to report RPO violations
                Baoth Novice

                From the email Alerts I set up, with RPO Violations, I get mailed the following:

                 

                Alarm Definition:

                ([Event alarm expression: RPO violated])

                 

                Event details:

                Virtual machine vSphere Replication RPO is violated by 1 minute(s)

                 

                I'm really more interested in "RPO Violated" than anything, and would really like it to ignore the 1 minute warning so to avoid unnecessary concern.

                • 5. Re: Script to report RPO violations
                  LucD Guru
                  Community WarriorsUser ModeratorsvExpert

                  I mean what exactly is in the FullFormattedMessage field?

                  • 6. Re: Script to report RPO violations
                    Baoth Novice

                    Had to generalise some names, but here's the output. The parts in quotes are from the FullFormattedMessage column:

                     

                    09/10/2019 00:26 "Sync started by VR Scheduler for virtual machine <VM-NAME> on host <HOST> in cluster <CLUSTER> in <DC>." <VM-NAME>

                    09/10/2019 00:27 "Virtual machine vSphere Replication RPO is violated by 1 minute(s)" <VM-NAME>

                    09/10/2019 00:30 "Virtual machine vSphere Replication RPO is no longer violated" <VM-NAME>

                    • 7. Re: Script to report RPO violations
                      LucD Guru
                      vExpertCommunity WarriorsUser Moderators

                      I forgot the escape the RegEx meta-characters in the condition.

                      Try like this

                       

                      Get-VIEvent -MaxSamples ([int]::MaxValue) |

                      Where { $_.EventTypeId -match "hbr|rpo" -and $_.FullFormattedMessage -match "Virtual machine vSphere Replication RPO is violated by 1 minute\(s\)" } |

                      Select CreatedTime, FullFormattedMessage,

                          @{Name="VMName";Expression={$_.Vm.Name}} |

                      Export-Csv -NoTypeInformation -Path ([Environment]::GetFolderPath("Desktop") + "\HBR-RPOEvents.csv")

                      1 person found this helpful
                      • 8. Re: Script to report RPO violations
                        Baoth Novice

                        That's returning data now. Great, thanks!

                         

                        Would the opening section like this work, to only cover the last 24 hours?

                         

                        Get-VIEvent -Start (Get-Date).adddays(-1) -MaxSamples ([int]::MaxValue |

                         

                         

                         

                        Is there any way to have a denominator that is anything other than 1 minute in the second match statement please?

                        • 9. Re: Script to report RPO violations
                          LucD Guru
                          Community WarriorsUser ModeratorsvExpert

                          Yes, that only retrieves the events from the last 24 hours.