DX Unified Infrastructure Management

Expand all | Collapse all

Detecting OS using LUA

  • 1.  Detecting OS using LUA

    Posted May 02, 2013 07:07 PM

    I am trying to write a script in AO to detect the OS flavor (Windows or UNIX) and then append a message depending on OS. but I'm having issues. When I use the following script, UNIX is being appended to the message of a windows box. But it is appended and appended until the message block is filled. Here is the script and message:

     

    local a = alarm.get()
    local system = ""
    local update = {}
    local message = ""
    update.nimid = a.nimid


    if System == "WINDOWS" then
    update.message = a.message.." Windows"
    else
    update.message = a.message.." UNIX"
    end
    alarm.set(update)

     

     

    Average (1 samples) total cpu is now 7.71%, which is above the warning threshold (1%) UNIX UNIX UNIX UNIX UNIX UNIX UNIX UNIX UNIX

     

     



  • 2.  Re: Detecting OS using LUA

    Posted May 02, 2013 07:23 PM

    How is the AO profile configured? If you have it running the script on arrival, it will run every time the alarm repeats (usually 5 minutes). Then you would get it appending over and over.

     

    I think you have two ways to address it:

     

    • Run the AO profile on arrival and set the matching criterial to a count of 1. Then it should only run on the arrival of the first message.
    • Run the AO profile on overdue age of some small amount of time like 5s. Then it will run only once, and a small delay should not matter.


  • 3.  Re: Detecting OS using LUA

    Posted May 02, 2013 09:21 PM

    The profile is configured to equal a count of 1. But it is like the script runs about 6 times before the 2nd count. Then  when it hits the 3rd count, the portion that was appended to the message, disappears (default message only).

     

    Also, what is the best way to identify the OS?  System == "WINDOWS" doesn't work.. Steps right over the if statement.



  • 4.  Re: Detecting OS using LUA

    Posted May 02, 2013 08:29 PM

    Try this instead.

     

    if System == "Windows" then

     

     Or you could get rid of the if statement and just append the message like this.

     

    update.message = a.message.." "..a.os_major



  • 5.  Re: Detecting OS using LUA

    Posted May 02, 2013 09:30 PM
    I tried that Chris, but the OS still wasn't identified. The final result that I'm looking for, is to be able to append a URL to an internal Wiki page based off the OS. Windows servers go to one wiki while a UNIX system goes to a different wiki based off the CDM probe. This is so our NOC can just click a link in the UMP that will take them to a page that will assist them with resolving the alarm. Hope I'm making this clear


  • 6.  Re: Detecting OS using LUA

    Posted May 02, 2013 10:19 PM

    I forgot that your tweak to the message will get clobbered by repeats of the alarm, so I guess you do need to run the AO profile on arrival without specifying a count. If you do this, do you get UNIX appended six times on every arrival or just on the first one?

     

    Are you also saying that you are having trouble getting the script to correctly identify Windows and Unix system? How are you setting the variable system in your script? In the example above, you have it hardcoded to an empty string, so it will never match Windows.



  • 7.  Re: Detecting OS using LUA

    Posted May 03, 2013 05:56 PM

    Thanks for your help Keith, but I'm just going to do this another way. 

     

    Andy



  • 8.  Re: Detecting OS using LUA

    Posted May 03, 2013 08:21 PM

    Sorry If I should start a new thread. but this LUA is really kicking my butt. Now all I am trying to do is append a URL to the message.

    For some reason when I run this script, the alarm is set to warning and the url is appended correctly, but since I do not want the change the severity level, I am deleting the line "update.level = NIML_WARNING". Once I do that, the url gets added to the message over and over. 

     

    Working code:

    local a = alarm.get()

    local update = {}

     

    update.nimid = a.nimid
    update.level = NIML_WARNING
    update.message = a.message.." http://wiki.test.com/CDM+Probe+Handling+Plans"

     

    alarm.set(update)

     

    Non working code:

    local a = alarm.get()

    local update = {}

     

    update.nimid = a.nimid
    update.message = a.message.." http://wiki.test.com/CDM+Probe+Handling+Plans"

     

    alarm.set(update)

     

    So not sure why the update.level is needed, but how can I add a url to the message and keep severity level the same?



  • 9.  Re: Detecting OS using LUA

    Posted May 03, 2013 09:23 PM

    Could you attach a screenshot of the AO profile? It might be a long shot, but sometimes that helps.

    It sounds like the AO profile might be running every time the alarm updates, even if the update originates internally. I do not think that is the intended behavior, but I could be wrong. I was under the impression that "on arrival" means the arrival of an alarm message rather than any kind of update.



  • 10.  Re: Detecting OS using LUA

    Posted May 03, 2013 09:38 PM
      |   view attached

    Attached screenshot with the AO profile and alert. 



  • 11.  Re: Detecting OS using LUA

    Posted May 03, 2013 10:30 PM

    Well, that explains why changing the severity of the alarm prevents the URL from being appended multiple times. The AO profile only matches when the alarm has a severity of minor.

     

    It still does not make much sense to me that the URL is appended multiple times, but I think the AO must match every time the alarm is updated even if that update originates internally. As I said earlier, I did not think that was the behavior, but I cannot be sure I ever directly witnessed anything different. Either I have just never come across this type of situation or the behavior has changed somewhere along the way.

     

    It looks like you are matching a count of 1, so what if you changed the AO profile to run on overdue age of 5s rather than on arrival? That should make sure the script runs only once. (You can remove the count from the match criteria then, although it should work the same even if you leave it there.) Note that you will probably lose the URL when the alarm repeats after five minutes, but that should happen with the profile configured as is anyway.



  • 12.  Re: Detecting OS using LUA

    Posted May 08, 2013 07:36 PM

    I appreciate your help Keith,  I was able to get this working using a NOT description for the message string of "http://". So now it doesn't duplicate.

    But I still am not able to determine the OS. Do you happen to have a script to determine the OS? This doesn't work

     

    local a = alarm.get()
    local update = {}
    local message = ""
    update.nimid = a.nimid

     

    if a.System == "WINDOWS" then
    update.message = a.message.." http://wiki.Windows"
    else
    update.message = a.message.." http://wiki.UNIX"
    end
    alarm.set(update)



  • 13.  Re: Detecting OS using LUA

    Posted May 09, 2013 12:10 PM

    Hi,

     

    OS info is not a property of the alarm. You need to get that from the hub, robot or DB. Here's an example:

     

    local info = alarm.get(<alarmid>)
    local os = nimbus.request("/"..info.domain.."/"..info.hub.."/"..info.robot.."/controller", "os_info")
    printf(os.OStype)

     -jon



  • 14.  Re: Detecting OS using LUA

    Posted Mar 19, 2015 05:14 PM

    Just curious...Were you ever successful in getting this to work?