class AIX::Errlog::Match

A class that is useful for building errlog matchers.

You usually won't need to access this class directly; you'll be able to create instances of it indirectly through the use of Errlog::match

You can build field matchers using the methods on the errlog and standard logical operators, and there are standard conversions for certain things like Time and DateTime operations. For instance, if you wanted errlog entries only in January 2018 with FOO in the label somewhere, you cold use a match like this with an Errlog instance.

errlog.match {
  (timestamp >= DateTime.new(2018, 1, 1)) &
  (timestamp < DateTime.new(2018, 2, 1)) &
  label.include?('FOO')
}

It really is that easy. The rest of the magic is done for you behind the scenes, as long as you follow the rules and know how to make these matches in the C equivalent. Note that there must always be a Match on the left side of all comparisons, so something like

DateTime.new(2018, 1, 1) <= errlog.match{timestamp}

is not possible.

This class should allow you to build matches for errlog_find_first in a simple and natural way. Note that & is the LE_OP_AND operator, and | is the LE_OP_OR operator, not &&, and, ||, or or, because those can't be overridden.

Attributes

left[RW]
operator[RW]
right[RW]

Public Class Methods

class() click to toggle source

Match convenience function. Gets a Leaf match for comparing against class.

# File lib/aix/errlog/match.rb, line 193
def self.class
  new(left: :class)
end
connwhere() click to toggle source

Match convenience function. Gets a Leaf match for comparing against connwhere.

# File lib/aix/errlog/match.rb, line 240
def self.connwhere
  new(left: :connwhere)
end
crcid() click to toggle source

Match convenience function. Gets a Leaf match for comparing against crcid.

# File lib/aix/errlog/match.rb, line 175
def self.crcid
  new(left: :crcid)
end
detail_data() click to toggle source

Match convenience function. Gets a Leaf match for comparing against detail_data.

# File lib/aix/errlog/match.rb, line 258
def self.detail_data
  new(left: :detail_data)
end
errdiag() click to toggle source

Match convenience function. Gets a Leaf match for comparing against errdiag.

# File lib/aix/errlog/match.rb, line 270
def self.errdiag
  new(left: :errdiag)
end
flag_err64() click to toggle source

Match convenience function. Gets a Leaf match for comparing against flag_err64.

# File lib/aix/errlog/match.rb, line 246
def self.flag_err64
  new(left: :flag_err64)
end
flag_errdup() click to toggle source

Match convenience function. Gets a Leaf match for comparing against flag_errdup.

# File lib/aix/errlog/match.rb, line 252
def self.flag_errdup
  new(left: :flag_errdup)
end
in() click to toggle source

Match convenience function. Gets a Leaf match for comparing against in.

# File lib/aix/errlog/match.rb, line 234
def self.in
  new(left: :in)
end
label() click to toggle source

Match convenience function. Gets a Leaf match for comparing against label.

# File lib/aix/errlog/match.rb, line 163
def self.label
  new(left: :label)
end
machineid() click to toggle source

Match convenience function. Gets a Leaf match for comparing against machineid.

# File lib/aix/errlog/match.rb, line 181
def self.machineid
  new(left: :machineid)
end
new(left:, operator: nil, right: nil) click to toggle source
# File lib/aix/errlog/match.rb, line 42
def initialize(left:, operator: nil, right: nil)
  @left = left
  @operator = operator
  @right = right
end
nodeid() click to toggle source

Match convenience function. Gets a Leaf match for comparing against nodeid.

# File lib/aix/errlog/match.rb, line 187
def self.nodeid
  new(left: :nodeid)
end
rclass() click to toggle source

Match convenience function. Gets a Leaf match for comparing against rclass.

# File lib/aix/errlog/match.rb, line 211
def self.rclass
  new(left: :rclass)
end
resource() click to toggle source

Match convenience function. Gets a Leaf match for comparing against resource.

# File lib/aix/errlog/match.rb, line 205
def self.resource
  new(left: :resource)
end
rtype() click to toggle source

Match convenience function. Gets a Leaf match for comparing against rtype.

# File lib/aix/errlog/match.rb, line 217
def self.rtype
  new(left: :rtype)
end
sequence() click to toggle source

Match convenience function. Gets a Leaf match for comparing against sequence.

# File lib/aix/errlog/match.rb, line 157
def self.sequence
  new(left: :sequence)
end
symptom_data() click to toggle source

Match convenience function. Gets a Leaf match for comparing against symptom_data.

# File lib/aix/errlog/match.rb, line 264
def self.symptom_data
  new(left: :symptom_data)
end
timestamp() click to toggle source

Match convenience function. Gets a Leaf match for comparing against timestamp.

# File lib/aix/errlog/match.rb, line 169
def self.timestamp
  new(left: :timestamp)
end
type() click to toggle source

Match convenience function. Gets a Leaf match for comparing against type.

# File lib/aix/errlog/match.rb, line 199
def self.type
  new(left: :type)
end
vpd_ibm() click to toggle source

Match convenience function. Gets a Leaf match for comparing against vpd_ibm.

# File lib/aix/errlog/match.rb, line 223
def self.vpd_ibm
  new(left: :vpd_ibm)
end
vpd_user() click to toggle source

Match convenience function. Gets a Leaf match for comparing against vpd_user.

# File lib/aix/errlog/match.rb, line 229
def self.vpd_user
  new(left: :vpd_user)
end
wparid() click to toggle source

Match convenience function. Gets a Leaf match for comparing against wparid.

# File lib/aix/errlog/match.rb, line 276
def self.wparid
  new(left: :wparid)
end

Public Instance Methods

!() click to toggle source
# File lib/aix/errlog/match.rb, line 147
def !
  Match.new(
    left: self,
    operator: :not,
  )
end
!=(other) click to toggle source
# File lib/aix/errlog/match.rb, line 96
def !=(other)
  @operator = :ne
  @right = other
  self
end
&(other) click to toggle source
# File lib/aix/errlog/match.rb, line 126
def &(other)
  Match.new(
    left: self,
    operator: :and,
    right: other,
  )
end
<(other) click to toggle source
# File lib/aix/errlog/match.rb, line 106
def <(other)
  @operator = :lt
  @right = other
  self
end
<=(other) click to toggle source
# File lib/aix/errlog/match.rb, line 111
def <=(other)
  @operator = :le
  @right = other
  self
end
==(other) click to toggle source
# File lib/aix/errlog/match.rb, line 91
def ==(other)
  @operator = :equal
  @right = other
  self
end
>(other) click to toggle source
# File lib/aix/errlog/match.rb, line 116
def >(other)
  @operator = :gt
  @right = other
  self
end
>=(other) click to toggle source
# File lib/aix/errlog/match.rb, line 121
def >=(other)
  @operator = :ge
  @right = other
  self
end
^(other) click to toggle source
# File lib/aix/errlog/match.rb, line 140
def ^(other)
  Match.new(
    left: self,
    operator: :xor,
    right: other,
  )
end
include?(other) click to toggle source
# File lib/aix/errlog/match.rb, line 101
def include?(other)
  @operator = :substr
  @right = other
  self
end
to_struct() click to toggle source

Uses the structure of this object to build a errlog_match_t structure. Does not check whether operators only work on leaves or any other specifics as that (for instance, an and operator needs two Match leaves, and won't work between a field and a Match or anything like that). The function itself might check some of the operators to make sure that they're set and throw an error for you, but something like a segfault is more likely if you screw up the structure. Make sure you know what you're doing.

# File lib/aix/errlog/match.rb, line 56
def to_struct
  raise "operator must be a symbol, but is #{@operator}" unless @operator.is_a? Symbol

  # We want to be sure the struct is not garbage collected before it's
  # used, so we need to retain a reference to it that ensures that it will
  # live as long as this object
  @struct = Lib::ErrlogMatch.new

  @struct[:em_op] = @operator

  case @left
  when Match
    @struct[:emu1][:emu_left] = @left.to_struct
  when Symbol
    @struct[:emu1][:emu_field] = @left
  else
    raise "left should be either a Match or Symbol object, but is a #{@left.class}"
  end

  case @right
  when Match
    @struct[:emu2][:emu_right] = @right.to_struct
  when String
    @struct[:emu2][:emu_strvalue] = @right
  when Numeric, Time
    @struct[:emu2][:emu_intvalue] = @right.to_i
  when DateTime
    @struct[:emu2][:emu_intvalue] = @right.to_time.to_i
  else
    raise "Right should be either a Match, String, Numeric, Time, or DateTime object, but is a #{@right.class}"
  end

  @struct
end
|(other) click to toggle source
# File lib/aix/errlog/match.rb, line 133
def |(other)
  Match.new(
    left: self,
    operator: :or,
    right: other,
  )
end