9 Replies Latest reply: Aug 8, 2011 11:15 AM by zen_foosball RSS

Tips on using AlertReceiver class

I have some code as follows:

server.Login(

 

"serverName", "appadmin", "somePassword");

alertReceiver =

new AlertReceiver(server);

alertReceiver.onConnect +=

new AlertReceiver.OnConnectEventHandler(OnConnect);

alertReceiver.onDisconnect +=

new AlertReceiver.OnDisconnectEventHandler(OnDisconnect);

alertReceiver.onDataReceived +=

new AlertReceiver.OnDataReceivedEventHandler(OnDataReceived);

alertReceiver.BeginReceive();

 

OnConnect is defined as follows:

public

 

 

static void OnConnect(object sender, AlertReceiver.OnConnectEventArgs e)

{

}

 

Problem is, the AlertReceiver OnConnect is never hit... why would that be?  Is there something special I need to do.  I'm able to use BMC Alert application UI connected to server, no port specified, and it shows me the alerts assigned to the appadmin account.

 

Also, how would I go about changing the Alerts such that I can see - for instance - when any Incident is created?  A few helpful steps to get started would be much appreciated.

 

Thanks!

 

  • 1. Re: Tips on using AlertReceiver class

    I am using .NET API v 7.5, against a 7.1.00 AR System server.  I'm wondering if I need to upgrade the server to 7.5 perhaps??

     

    Another item of note - when I connect to 7.1 Remedy Administrator app, I get the message:

    "This version of the Action Request System(R) is ready for use or evaluation without purchasing or activating an authorization key.  For unlimited capabilities, contact your sales representative or visit www.bmc.com.  (ARERR 2877)"

     

    I would think that since the BMC Remedy Alert app is working, that the alerting mechanisms are all functioning, but maybe not (?).

     

    Also, I found the following on the message boards here, but to me this does not necessarily indicate that the server needs to be upgraded - more like a client issue that was fixed:

     

    AR System .NET and COM API 7.5

    http://communities.bmc.com/communities/docs/DOC-6013

    7.1.2818.30284 - fixed AlertReceiver implementation (Thanks to Jan Hartung who reported the defect and suggested working implementation);

     

    Any thoughts?  Suggestions?  Shouldn't OnConnect be getting called?  Is this a known bug / defect?  Do I need a different license and / or upgraded server?

     

    Thanks,

    Mike

  • 2. Re: Tips on using AlertReceiver class
    Carl Wilson

    Hi,

    the 7.5 API is backwards compatible, so no need to upgrade the server.

    The message you are receiving means that you do not have a valid AR Server license entered into the system, so you are using the default licensing restrictions supplied with the installation.  This means you are restricted on the number of fixed licenses you can allocate to people.

    The other thread is showing you the history of the API updates, so the 7.5 API will include the fixes that you see.

     

    Have you tried the sample that is provided with the API Help?

     

    I would suggest putting an error handler in the below code to capture if the server login occured correctly or not.  If it didn't, you will not be able to instantiate the alertreceiver events.

    Example

    [C#]

    using System;
    using BMC.ARSystem;
    
    namespace BMC.ARSystem.Samples
    {
       class AlertReceiverTester
       {
          static void Main(string[] args)
          {
             /* Instantiate a server object */
             BMC.ARSystem.Server server = new BMC.ARSystem.Server();
             server.Login("ServerNameHere", "UserNameHere", "PasswordHere", "");
             /* Instantiate an alert receiver object */
             AlertReceiver alertReceiver = new AlertReceiver(server);
             alertReceiver.onConnect += new AlertReceiver.OnConnectEventHandler(OnConnect);
             alertReceiver.onDisconnect += new AlertReceiver.OnDisconnectEventHandler(OnDisconnect);
             alertReceiver.onDataReceived += new AlertReceiver.OnDataReceivedEventHandler(OnDataReceived);
             /* Start receiving alerts via OnDataReceived callbacks */
             Console.WriteLine ("Start receiving alerts. Press [Enter] to exit" );
             alertReceiver.BeginReceive();
             /* Simulate wait event until when you would want to keep listening for alerts */
             Console.ReadLine();
             /* To stop receiving alerts */
             alertReceiver.EndReceive();
          }
    
          public static void OnConnect(object sender, AlertReceiver.OnConnectEventArgs e)
          {
             Console.WriteLine( "AR Server {0}, Connected", e.Client );
          }
    
          private static void OnDataReceived(object sender, AlertReceiver.OnDataReceivedEventArgs e)
          {
             Console.WriteLine( "AR Server {0}, Data received : {1}", e.Client, e.Data.ToString() );
          }
    
          private static void OnDisconnect(object sender, AlertReceiver.OnDisconnectEventArgs e)
          {
             Console.WriteLine( "AR Server {0}, Disconnected", e.Client );
          }
       }
    }
  • 4. Re: Tips on using AlertReceiver class

    Thanks Carl.

     

    I think I essentially have the C# code you used in the message, with the addition of the following line after the login, as well as of course providing my server name / user / password in the Login call:

    Console.WriteLine(string.Format("You currently have {0} pending alerts...", server.GetAlertCount("").ToString()));

     

    When I run the application this says "You currently have 11 pending alerts", so I think the login is working.  However I would also expect the OnConnect handler to be getting called.

     

    So any other suggestions?  I see you've just posted another message so I'll check that as well, but this is a pretty trivial code sample that appears to not be working.  Is there anything else on the AR Server that could be configured incorrectly for alerting?

  • 5. Re: Tips on using AlertReceiver class
    Carl Wilson

    Hi,

    OnConnect would not be triggered until you received an alert, as not would the OnDataReceived?

    So, you would need to instantiate the receiver before any of the methods (OnConnect, OnDataReceived, OnDisconnect) can occur - which looking at the code is done by this command:

     

    alertReceiver.BeginReceive();

    What happens when you instantiate the receiver to start receiving alerts, simulate a wait state, and an alert is generated?

    This is where the methods would then be callled from my understanding.

     

    > Console.WriteLine(string.Format("You currently have {0} pending alerts...", server.GetAlertCount("").ToString()));

     

    The server.GetAlertCount is in the Server class and a completely different/separate member to anything in the AlertReceiverClass.  You instantiate this class with the server.Login call, which then allows you to show the results for the members of that class (to which there are many) and GetAlertCount being one of them.

  • 6. Re: Tips on using AlertReceiver class

    Thanks.

     

    The GetAlertCount is being performed in part to verify that the server.Login is working.  I understand that the AlertReceiver

    is a separate class.  As I said, I am using identical code to the C# sample posted except for the GetAlertCount call and providing correct server name and credentials.  I am calling BeginReceive, as in the sample.

     

    Are you sure that OnConnect only gets called after a matching alert is generated?  If so, that may explain my problem - I'm expecting the AlertReceiver to immediately connect regardless of whether alerts are being currently generated or not.  Is that not a correct assumption?  Seems a little awkward that it would not immediately Connect and start listening.

  • 7. Re: Tips on using AlertReceiver class

    Just for clarification:

     

    The AlertReceiver takes a  server in its constructor, and earlier you asked me to verify that server.Login was working, just FYI:

     

    AlertReceiver alertReceiver = new AlertReceiver(server);

     

    The server.GetAlertCount should verify that the login has succeeded.

  • 8. Re: Tips on using AlertReceiver class

    >>What happens when you instantiate the receiver to start receiving alerts, simulate a wait state, and an alert is generated?

    This is where the methods would then be callled from my understanding.

     

    Carl, I generated an alert by creating an incident from within the Remedy User GUI, and I verified that the alert is displayed in the BMC Remedy Alert application.  At the same time, I had my test application waiting on the Console.Readline line, after BeginReceive has been called.  OnConnect / OnDataReceived etc are never hit in my test application.

  • 9. Re: Tips on using AlertReceiver class
    zen_foosball

    Hi,

     

    I'm also having problem using the AlertReceiver and I followed the sample code as shown.  When I call the AlertReceiver.BeginReceive() nothing seems to happen.  I looked into the alert debug log and it seems like it cannot forward the alert to my sample code.

     

    I experimented with another method, I created a TcpListener and use the ARServer.RegisterForAlerts.  Every time I receive a message, I send an "ack" back to the ARSystem:

     

              client.Client.Send( Encoding.ASCII.GetBytes( "ack" ) );

     

    This seems to work and I can see in the debug log that it acknowledges my acknowledge and continue to send me alerts.

     

    However, here is my dilemma,  anyone know how to decode the bytes?  All I know is that the first 4 bytes are some kind of identifier while the next 4 bytes tells me the total length of the entire message.  The rest is a mystery.

     

    Any guidance is greatly appreciated.

     

    Thanks,

     

    Joseph