Operators combine a group of inspectors and an operator to implement data evaluation patterns. Using the examples from Inspectors, we can create these patterns:

  • string matches /^[Fo][Oo][Oo]/ AND length(value) >= 3
  • NOT IP address is public AND NOT IP address is private
  • NOT data is gzip OR NOT length(value) >= 3

Settings

  • all: data passes inspection if every inspector returns true
  • any: data passes inspection if any inspector returns true
  • none: data passes inspection if no inspector returns true

Complex evaluation patterns are possible by combining operators with several inspectors. For example, this operator returns true if an IP address is public:

local sub = import 'substation.libsonnet';

local op = sub.interfaces.operator.none([
  // check if the IP address is none of these non-public types
  sub.interfaces.inspector.ip(options={ type: 'loopback' }, settings={ key: 'addr' }),
  sub.interfaces.inspector.ip(options={ type: 'multicast' }, settings={ key: 'addr' }),
  sub.interfaces.inspector.ip(options={ type: 'multicast_link_local' }, settings={ key: 'addr' }),
  sub.interfaces.inspector.ip(options={ type: 'private' }, settings={ key: 'addr' }),
  sub.interfaces.inspector.ip(options={ type: 'unicast_link_local' }, settings={ key: 'addr' }),
  sub.interfaces.inspector.ip(options={ type: 'unspecified' }, settings={ key: 'addr' }),
  // negation combined with the none operator results in this matching valid IP addresses
  sub.interfaces.inspector.ip(options={ type: 'valid' }, settings={ key: 'addr', negate: true }),
]);

op
{
   "inspectors": [
      {
         "settings": {
            "key": "addr",
            "options": {
               "type": "loopback"
            }
         },
         "type": "ip"
      },
      {
         "settings": {
            "key": "addr",
            "options": {
               "type": "multicast"
            }
         },
         "type": "ip"
      },
      {
         "settings": {
            "key": "addr",
            "options": {
               "type": "multicast_link_local"
            }
         },
         "type": "ip"
      },
      {
         "settings": {
            "key": "addr",
            "options": {
               "type": "private"
            }
         },
         "type": "ip"
      },
      {
         "settings": {
            "key": "addr",
            "options": {
               "type": "unicast_link_local"
            }
         },
         "type": "ip"
      },
      {
         "settings": {
            "key": "addr",
            "options": {
               "type": "unspecified"
            }
         },
         "type": "ip"
      },
      {
         "settings": {
            "key": "addr",
            "negate": true,
            "options": {
               "type": "valid"
            }
         },
         "type": "ip"
      }
   ],
   "operator": "none"
}