VMware {code} Community
Slingsh0t
Enthusiast
Enthusiast

Retrieve list of alarm descriptions in C#

How do I do it?  It seems like such a simple thing yet I'm struggling (I can do other things like get VMs, DC's, etc but I am still learning...).  I can get the alarm ID's, just having trouble with the descriptions.

Can someone please point me in the right direction?

0 Kudos
6 Replies
lamw
Community Manager
Community Manager

How are you retrieving the alarms?

One method is to use the AlarmManger and the GetAlarm() method - http://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc_50%2Fvim.alarm.Alar... which will return you an array of Alarms. If you loop through each one, you will see that you can retrieve the description for the alarm which is extended in the AlarmSpec http://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc_50%2Fvim.alarm.Alar...

(e.g. alarm->info->AlarmSpec->description)

0 Kudos
stripeyfish
Contributor
Contributor

Once you have a list of mObj for the Alarms, then retrieve AlarmInfo from the mObj for each Alarm using 'info' property. AlarmInfo inherits the 'description' property from AlarmSpec.

I can dig out some code if you like Smiley Happy

Stripey


0 Kudos
Slingsh0t
Enthusiast
Enthusiast

Thanks for the responses guys,  Here is the code I've got so far, any ideas why its not working?:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VMware.Vim;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            VimClient c = new VimClient();
            ServiceContent sc = c.Connect("redacted", null, null);
            UserSession us = c.Login("redacted", "redacted");

            ManagedObjectReference alarmMOR = new ManagedObjectReference();
            alarmMOR.Type = "Alarm";
            alarmMOR.Value = "alarm-3";

            AlarmManager alarmMg = new AlarmManager(c,alarmMOR);
            Console.WriteLine(alarmMg.Description); <- alarmMg.Description always seems to come back as null!

            c.Disconnect();
           
        }
    }
}
0 Kudos
stripeyfish
Contributor
Contributor

If you want to get a list of descriptions for all alarms currently defined, then you first need to get a reference to the AlarmManager from the ServiceContent obtained from your connection to vCenter.

The use GetAlarm on the AlarmManager to get an array of ManagedObject IDs for all the alarms.

Then loop through this list of mObj, to obtain the AlarmInfo (using info) using a property collector function. Info.Description will be the description for each alarm.

What are you trying to do with Alarms?

If its import and export I have that covered - see link below Smiley Wink

Stripey

0 Kudos
samsvmware
Enthusiast
Enthusiast

Do you have any perl api script to get the list of alarm (VM alarm) with description ?

0 Kudos
afarinesh
Contributor
Contributor

Please give a complete answer with code sample ....

0 Kudos