Class: SpecTools::Alarm

Inherits:
Object
  • Object
show all
Extended by:
SpecToolsExtensions
Includes:
SpecToolsExtensions
Defined in:
lib/spectools.rb,
lib/vnmsh.rb

Overview

SpecTools::Alarm

Represents a Spectrum alarm

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SpecToolsExtensions

call_default_extension, call_extension, method_missing, method_missing

Constructor Details

#initialize(id = nil, time = nil, causeid = nil, model = Model.new, severity = nil, ack = false, stale = false, assignment = nil, status = nil, message = nil, url = nil, ticket = nil, clearable = nil, state = nil, landscape = Landscape.new) ⇒ Alarm

Returns a new instance of Alarm.



458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/spectools.rb', line 458

def initialize(id = nil, time = nil, causeid = nil, model = Model.new, severity = nil, ack = false, stale = false, assignment = nil, status = nil, message = nil, url = nil, ticket = nil, clearable = nil, state = nil, landscape = Landscape.new)
  @id = id
  @time = time
  if causeid.nil? || causeid.hex?
    @causeid = causeid
  else
    raise ArgumentError, "causeid is not a hex code."
  end
  if model.nil? || model.kind_of?(Model)
    @model = model
  else
    raise ArgumentError, "model is not a Model object"
  end
  @severity = severity
  @ack = ack
  @stale = stale
  @assignment = assignment
  @status = status
  @message = message
  @url = url
  @ticket = ticket
  @landscape = landscape
  @clearable = clearable
  @state = state
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SpecToolsExtensions

Instance Attribute Details

#ackObject

Set to true if the alarm has been acknowledged



442
443
444
# File 'lib/spectools.rb', line 442

def ack
  @ack
end

#assignmentObject

Who the alarm is assigned to



438
439
440
# File 'lib/spectools.rb', line 438

def assignment
  @assignment
end

#causeidObject

The alarm’s Probable Cause ID



432
433
434
# File 'lib/spectools.rb', line 432

def causeid
  @causeid
end

#clearableObject

Set to true if the alarm is clearable by a user.



454
455
456
# File 'lib/spectools.rb', line 454

def clearable
  @clearable
end

#idObject

The alarm’s ID



427
428
429
# File 'lib/spectools.rb', line 427

def id
  @id
end

#landscapeObject

The landscape on which the alarm was thrown



452
453
454
# File 'lib/spectools.rb', line 452

def landscape
  @landscape
end

#messageObject

The Probable Cause text for the alarm



446
447
448
# File 'lib/spectools.rb', line 446

def message
  @message
end

#modelObject

The Model the alarm was asserted against



434
435
436
# File 'lib/spectools.rb', line 434

def model
  @model
end

#severityObject

The alarm’s severity



436
437
438
# File 'lib/spectools.rb', line 436

def severity
  @severity
end

#staleObject

Set to true if the alarm is stale



444
445
446
# File 'lib/spectools.rb', line 444

def stale
  @stale
end

#stateObject

The state of the alarm



456
457
458
# File 'lib/spectools.rb', line 456

def state
  @state
end

#statusObject

The alarm’s status



440
441
442
# File 'lib/spectools.rb', line 440

def status
  @status
end

#ticketObject

The ticket number associated with this alarm



450
451
452
# File 'lib/spectools.rb', line 450

def ticket
  @ticket
end

#timeObject

The time the alarm was generated. This time is local!



430
431
432
# File 'lib/spectools.rb', line 430

def time
  @time
end

#urlObject

The URL for extra information about this alarm



448
449
450
# File 'lib/spectools.rb', line 448

def url
  @url
end

Class Method Details

.cli_destroy(aid, landscape = nil, session = nil) ⇒ Object

Use CLI to destroy an alarm.



737
738
739
740
# File 'lib/vnmsh.rb', line 737

def self.cli_destroy(aid,landscape=nil,session=nil)
  session = VNMSH.get_session(session)
  session.destroy_alarm(aid,landscape)
end

.cli_find(type = :standard, mh_or_lh = nil, probcause = false, session = nil) ⇒ Object

Use CLI to find Alarms. Returns an array of Alarm objects. Available find types:

  • :standard - Retrieves the standard list of alarms.

  • :all - Retrieves all alarms, including MAINTENANCE.

  • :model - Retrieves standard alarms for a given model.

  • If set, mh_or_lh must be a valid Model or model handle.

  • :model - Identical to :model, except returns all alarms.

  • :landscape - Retrieves standards alarms for a given landscape.

  • If set, mh_or_lh must be a valid Landscape or landscape handle.

Setting probcause to true will include the Probable Cause information in the message attribute of each Alarm.



705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
# File 'lib/vnmsh.rb', line 705

def self.cli_find(type=:standard,mh_or_lh=nil,probcause=false,session=nil)
  session = VNMSH.get_session(session)
  alarms = Array.new
  alarm_output = session.show_alarms(type,mh_or_lh,probcause)
  causes = Hash.new
  alarm_output.each do |line|
    if line =~ /\d+\s+\d\d\/\d\d\/\d\d\d\d/ 
      alarm = Alarm.parse(line)
      if type == :landscape
        if mh_or_lh.kind_of?(Landscape)
          alarm.landscape = mh_or_lh
        else
          alarm.landscape = Landscape.new(mh_or_lh)
        end
      else
        alarm.landscape = session.current_landscape
      end
      alarms.push(alarm)
    elsif line =~ /^(0x[a-fA-F0-9]+)\s/
      causeid = $1
      causes[causeid] = line.sub(/^(0x[a-fA-F0-9]+)\s/,"")
    end
  end
  if probcause
    alarms.each do |alarm|
      alarm.message = causes[alarm.causeid]
    end
  end
  return alarms
end

.cli_parse(line) ⇒ Object

Take a line of CLI show output and populate a new Alarm object



660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
# File 'lib/vnmsh.rb', line 660

def self.cli_parse(line)
  alarm = Alarm.new
  #OK, here we go. Unfortunately, we have no guidelines to parse this data. It doesn't tend to be fixed-width, and
  #there are no delimteres for a good regex. So, here we have to mix the 2 as best we can.
  #First, we can use a regex to grab out the first few fields.
  line =~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)$/
  alarm.id = $1
  date = $2
  time = $3
  alarm.causeid = $4
  alarm.model.handle = $5
  rest = $6
  month,day,year = date.split(/\//)
  hour,min,sec = time.split(/:/)
  alarm.time = Time.local(year,month,day,hour,min,sec)
  #Alright, now we know that the model name is 1024 characters, so I can grab that with unpack
  alarm.model.name,rest = rest.unpack('A1025A8192')
  #Now, we have to use a regex to extract the model type name, as it will extend and not truncate. 
  #We're lucky that Model type names usually don't contain whitespace.
  rest =~ /^(\S+)\s+(.*)$/
  alarm.model.type.name = $1
  rest = $2
  #Now, whether we like it or not, we have to use unpack for the rest
  alarm.severity,ack,stale,alarm.assignment,alarm.status = rest.unpack('A14A4A6A25A4096')
  if ack =~ /Yes/
    alarm.ack = true
  end
  if stale =~ /Yes/
    alarm.stale = true
  end
  return alarm
end

Instance Method Details

#ack?Boolean

Returns true if the alarm has been acknowledged

Returns:

  • (Boolean)


485
486
487
# File 'lib/spectools.rb', line 485

def ack?
  @ack
end

#cli_destroy(landscape = nil, session = nil) ⇒ Object

Use CLI to destroy this alarm.



743
744
745
# File 'lib/vnmsh.rb', line 743

def cli_destroy(landscape=nil,session=nil)
  self.class.cli_destroy(id,landscape,session)
end

#cli_save(session = nil) ⇒ Object

Use CLI to save all attributes of this alarm.



748
749
750
751
752
753
754
755
756
757
# File 'lib/vnmsh.rb', line 748

def cli_save(session=nil)
  session = VNMSH.get_session(session)
  result = true
  result = session.update_alarm(id, :ticket, ticket, true) && result if ticket != nil
  result = session.update_alarm(id, :assign, assignment, true) && result if assignment != nil
  result = session.update_alarm(id, :status, status, true) && result if status != nil
  result = session.update_alarm(id, :ack, ack) && result if ack != nil
  result = session.update_alarm(id, :url, url, true) && result if url != nil
  result
end

#stale?Boolean

Returns true if the alarm is stale

Returns:

  • (Boolean)


490
491
492
# File 'lib/spectools.rb', line 490

def stale?
  @stale
end