LUA Regular Expressions (NAS Correlation)

Discussion created by 1_tim.moor on Nov 24, 2009
Latest reply on Nov 24, 2009 by carstein.seeberg
Hi there guys, I am writing a NAS script to correlate a
number of alarms that are generated when a LAN goes off line. I am monitoring 3
servers within 50 different LAN's and in the event that 3 servers become
unreachable I want to close the failed ping alarms and raise a Critical WAN
link alarm.

The way that I am approaching this is to create a trigger to hold all of the
failed pings for all servers. I then want to step through each server that has
failed, validate that it is in fact unreachable and using a regular expression
group the alarms into locations using the hostname.

What I have so far is:

-- WAN Link Alarm Correlation

if trigger.count("connect.wan.all") > 2 then
    t = trigger.alarms("connect.wan.all")
    for i,a in pairs(t) do
        s = a.hostname
        for j in string.gmatch(s, "*%d") do             

----------- Executing script at 24/11/2009 10:06:42 a.m. ----------

The problem as you may be able to see is that I am not familiar with the
string.match function in LUA. I have a PERL background and have a pretty good
understanding of how regular expressions work.

What I want is to only select the first 6 characters of the hostname. e.g nwtima. I would
normally do this using the substr function like substr(5,hostname) however the
LUA substr and PERL substr functions perform different actions.

Any help you can offer me will be greatly appreciated.