Changeset 7443b58 in nscp for scripts/lib


Ignore:
Timestamp:
03/24/11 21:38:31 (2 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
2d69ab6
Parents:
569a179
Message:

0.4.x a lot of tweaks and fixes (now works as a replacement for 0.3.x in many ways)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • scripts/lib/NagiosPlugins.vbs

    r9661f81 r7443b58  
    114114  Public Function get_threshold (threshold) 
    115115    ' Simple function to return the warning and critical threshold 
    116     If threshold = LCase("warning") Then 
     116    If LCase(threshold) = "warning" Then 
    117117      get_threshold = threshold_warning 
    118118    End IF 
    119119     
    120     If threshold = LCase("critical") Then 
     120    If LCase(threshold) = "critical" Then 
    121121      get_threshold = threshold_critical 
    122122    End If 
     
    136136  End Function 
    137137 
    138    
     138 
     139 
     140  Public Function get_threshold_perfdat(string) 
     141 
     142    Dim cintw0 
     143    Dim cintw 
     144    Dim x 
     145    Dim colon 
     146     
     147    cintw0=get_threshold(string) 
     148    x=Replace(cintw0,"~","") 
     149    cintw0=Replace(x,"@","") 
     150     
     151    colon=Instr(cintw0,":") 
     152     
     153    If (colon > 1) Then 
     154      cintw=Left(cintw0,colon-1) 
     155    Else 
     156      If (colon=1) Then 
     157        cintw=Mid(cintw0,2) 
     158      Else 
     159        cintw=cintw0 
     160      End If 
     161    End If 
     162     
     163    get_threshold_perfdat=cintw 
     164   
     165  End Function 
     166   
     167 
    139168  Public Function check_threshold (value) 
    140169    ' Verify the thresholds for warning and critical 
     
    152181    check_threshold = 0 
    153182     
     183    value = CDbl(value) 
     184     
    154185    Set re = New RegExp 
    155186    re.IgnoreCase = True 
     
    232263        Set threshold = re.Execute(threshold) 
    233264         
    234         If threshold(0) < 0 Or threshold(0) > value Then 
     265        If value < 0 Or value > CDbl(threshold(0)) Then 
     266          parse_range = 1 
     267        Else 
    235268          parse_range = 0 
    236         Else 
    237           parse_range = 1 
    238269        End If 
    239270 
     
    242273        re.Pattern = "^([0-9]+):$" 
    243274        Set threshold = re.Execute(threshold) 
    244         If value > threshold(0) Then 
    245           parse_range = 0 
    246         Else 
    247           parse_range = 1 
    248         End If 
    249  
    250       Case 3 
    251         ' outside the range infinity <- value 
    252         re.Pattern = "^~:([0-9]+)$" 
    253         Set threshold = re.Execute(threshold) 
    254         If value < threshold(0) Then 
    255           parse_range = 0 
    256         Else 
    257           parse_range = 1 
    258         End If 
    259  
    260       Case 4 
    261         ' outside the range of value:value 
    262         re.Pattern = "^([0-9]+):([0-9]+)$" 
    263         Set threshold = re.Execute(threshold) 
     275 
    264276         
    265277        For Each thres In threshold 
    266           If value < thres.SubMatches(0) Or value > thres.SubMatches(1) Then 
     278                                        'Wscript.Echo "SubMatches(0): " & thres.SubMatches(0) & " val: " & value 
     279          If value < CDbl(thres.SubMatches(0)) Then 
    267280            parse_range = 1 
    268281          Else 
     
    271284        Next 
    272285         
     286 
     287 
     288      Case 3 
     289        ' outside the range infinity <- value 
     290        re.Pattern = "^~:([0-9]+)$" 
     291        Set threshold = re.Execute(threshold) 
     292 
     293        For Each thres In threshold 
     294          If value > CDbl(thres.SubMatches(0)) Then 
     295            parse_range = 1 
     296          Else 
     297            parse_range = 0 
     298          End If 
     299        Next 
     300 
     301 
     302      Case 4 
     303        ' outside the range of value:value 
     304        re.Pattern = "^([0-9]+):([0-9]+)$" 
     305        Set threshold = re.Execute(threshold) 
     306         
     307        For Each thres In threshold 
     308          If value < CDbl(thres.SubMatches(0)) Or value > CDbl(thres.SubMatches(1)) Then 
     309            parse_range = 1 
     310          Else 
     311            parse_range = 0 
     312          End If 
     313        Next 
     314         
    273315      Case 5 
    274316        re.Pattern = "^@([0-9]+):([0-9]+)$" 
     
    276318         
    277319        For Each thres In threshold 
    278           If value > thres.SubMatches(0) And value < thres.SubMatches(1) Then 
    279             Wscript.Echo "Bigger than " & thres.SubMatches(0) & " and smaller than " & thres.SubMatches(1) 
     320          If value >= CDbl(thres.SubMatches(0)) And value <= CDbl(thres.SubMatches(1)) Then 
     321            'Wscript.Echo "Bigger than " & thres.SubMatches(0) & " and smaller than " & thres.SubMatches(1) 
    280322            parse_range = 1 
    281323          Else 
Note: See TracChangeset for help on using the changeset viewer.