Helper Functions
SentriFlow provides helper functions to simplify common checks in TypeScript rules. These functions encapsulate platform-specific logic for port types, command parsing, and configuration patterns.
SentriFlow includes vendor-specific helpers for all supported platforms (Cisco, Juniper, Palo Alto, Aruba, Arista, Fortinet, and more). For the complete vendor-specific helper reference, see the Rule Authoring Guide on GitHub.
Common Utilities
These utilities work across all vendors and are available from @sentriflow/core:
import {
parseIp,
parseInteger,
isDefaultVlan,
includesIgnoreCase,
startsWithIgnoreCase,
} from '@sentriflow/core';parseIp
Parse and validate an IP address.
function parseIp(ip: string): { valid: boolean; address?: string; prefix?: number }Example:
const result = parseIp('192.168.1.1/24');
if (!result.valid) {
return { passed: false, message: 'Invalid IP address' };
}parseInteger
Safely parse an integer with optional bounds checking.
function parseInteger(value: string, min?: number, max?: number): number | undefinedExample:
const vlanId = parseInteger(params[3], 1, 4094);
if (vlanId === undefined) {
return { passed: false, message: 'Invalid VLAN ID' };
}isDefaultVlan
Check if a VLAN ID is the default (VLAN 1).
function isDefaultVlan(vlanId: string | number): booleanincludesIgnoreCase
Case-insensitive string includes check.
function includesIgnoreCase(haystack: string, needle: string): booleanstartsWithIgnoreCase
Case-insensitive string startsWith check.
function startsWithIgnoreCase(str: string, prefix: string): booleanGeneric ConfigNode Helpers
These helpers work with any vendor’s ConfigNode structure:
import {
hasChildCommand,
getChildCommand,
} from '@sentriflow/core/helpers/common';hasChildCommand
Check if a node has a child command matching a prefix.
function hasChildCommand(node: ConfigNode, prefix: string): booleanExample:
// Check if interface has description
if (!hasChildCommand(node, 'description')) {
return { passed: false, message: 'Missing description' };
}getChildCommand
Get a child command node by prefix, or undefined if not found.
function getChildCommand(node: ConfigNode, prefix: string): ConfigNode | undefinedExample:
const descNode = getChildCommand(node, 'description');
if (descNode) {
const description = descNode.params.slice(1).join(' ');
}Vendor-Specific Helpers
Each supported vendor has specialized helpers. Import from the vendor-specific module:
| Vendor | Import Path |
|---|---|
| Cisco IOS/NX-OS | @sentriflow/core/helpers/cisco |
| Juniper Junos | @sentriflow/core/helpers/juniper |
| Palo Alto PAN-OS | @sentriflow/core/helpers/paloalto |
| Aruba AOS-CX | @sentriflow/core/helpers/aruba |
| Arista EOS | @sentriflow/core/helpers/arista |
| Fortinet FortiGate | @sentriflow/core/helpers/fortinet |
| VyOS | @sentriflow/core/helpers/vyos |
| MikroTik RouterOS | @sentriflow/core/helpers/mikrotik |
Example:
// Cisco-specific helpers
import { isTrunkPort, isAccessPort, isPhysicalPort } from '@sentriflow/core/helpers/cisco';
// Juniper-specific helpers
import { hasSetCommand, getSetValue } from '@sentriflow/core/helpers/juniper';
// Palo Alto-specific helpers
import { isSecurityRule, getZone } from '@sentriflow/core/helpers/paloalto';For detailed documentation on all vendor-specific helpers, see the Rule Authoring Guide .
Creating Custom Helpers
For organization-specific patterns, create custom helpers:
import type { ConfigNode } from '@sentriflow/core';
import { hasChildCommand } from '@sentriflow/core/helpers/common';
/**
* Check if interface is in a production VLAN.
*/
export function isProductionVlan(node: ConfigNode): boolean {
const PRODUCTION_VLANS = [100, 200, 300];
const accessVlan = node.children.find(c =>
c.id.startsWith('switchport access vlan')
);
if (accessVlan) {
const vlanId = parseInt(accessVlan.params[3] || '', 10);
return PRODUCTION_VLANS.includes(vlanId);
}
return false;
}Next Steps
- JSON Rules - Declarative rules without code
- TypeScript Rules - Advanced rule patterns
- Rule Authoring Guide - Complete reference