Graph

Description

Implements the functions for Graph rules.

Synopsis

use Assure1::Graph;

Functions

CloneVertexID

Convenience function to clone a vertex or linked vertex tree all at once. Returns a vertex hash of the new created vertices which contain references to their directional children & depths

CloneVertexID(\%options)

Options

NDB          -> Neo4j Database Handle Reference (i.e. \$NDB).
VertexID     -> VertexID to clone
CloneTree    -> Indicate whether to clone directionally linked vertices of VertexID as well (0=single, 1=tree)
                NOTE: children vertices cannot be modified during clone, and does not support circular linking
Vertex       -> New Vertex Definition containing Name (required), TimestampModified values, and a Properties hash (optional)

Returns

1. ErrorFlag   (0 Good, 1 Bad)
2. Message     (String)
3. TopVertexID (String)

Synopsis

my ($ErrorFlag, $Message, $TopVertexID) = CloneVertexID({
    NDB         => \$NDB,
    VertexID    => "#10:0",
    Vertex      => {
        Name       => $VertexName,
        Type       => $VertexTypeID
        Properties => {
            Key1 => "Value 1",
            Key2 => "Value 2"
        }
    }
});

if (!$TopVertexID) {
    $Log->Message('ERROR', "Error Cloning Vertex Tree: $Message");
}

OR

my $TopVertexID = CloneVertexID({
    NDB         => \$NDB,
    VertexID    => "#10:0",
    CloneTree   => 1,
    Vertex      => {
        Name       => $VertexName,
        Type       => $VertexTypeID
        Properties => {
            Key1 => "Value 1",
            Key2 => "Value 2"
        }
    }
});

if (!$TopVertexID) {
    $Log->Message('ERROR', "Error Cloning Vertex Tree");
}

CreateEdgeTree

Convenience function to create an Edge Tree with Properties all at once.

CreateEdgeTree(\%options)

Options

NDB          -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash  -> Cache (i.e. $StorageHash)
EdgeTree     -> Edge Definition & Properties hash (Edge definition can optionally contain VertexType1, VertexType2 and EdgeType)

Returns

1. ErrorFlag  (0 Good, 1 Bad)
2. Message    (String)
3. EdgeID     (String) or undef if error

Synopsis

my ($ErrorFlag, $Message, $EdgeID) = CreateEdgeTree({
    NDB          => \$NDB,
    StorageHash  => $StorageHash,
    EdgeTree     => {
        VertexID1   => $VertexID1,
        VertexID1   => $VertexID2,
        TypeID      => $EdgeTypeID,
        Properties  => {
            Key1  => "Value 1",
            Key2  => "Value 2"
        }
    }
});

if (!$EdgeID) {
    $Log->Message('ERROR', "Error Creating EdgeTree: $Message");
}

OR

my $EdgeID = CreateEdgeTree({
    NDB          => \$NDB,
    StorageHash  => $StorageHash,
    EdgeTree     => {
        VertexID1   => $VertexID1,
        VertexType1 => $VertexType1,
        VertexID2   => $VertexID2,
        VertexType2 => $VertexType2,
        TypeID      => $EdgeTypeID,
        EdgeType    => $EdgeType
        Properties  => {
            Key1  => "Value 1",
            Key2  => "Value 2"
        }
    }
});

if (!$EdgeID) {
    $Log->Message('ERROR', "Error Creating Edge");
}

CreateVertexTree

Convenience function to create vertex tree with properties all at once.

CreateVertexTree(\%options)

Options

DBH         -> Unified Assurance Database Handle Reference (i.e. \$DBH)
NDB         -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash -> Cache (i.e. $StorageHash)
VertexTree  -> Vertex Definition & Properties hash

Returns

1. ErrorFlag   (0 Good, 1 Bad)
2. Message     (String)
3. VertexID    (String) or undef if error

Synopsis

my ($ErrorFlag, $Message, $VertexID) = CreateVertexTree({
    DBH         => \$DBH,
    NDB         => \$NDB,
    StorageHash => $StorageHash,
    VertexTree  => {
        Name       => "Vertex 1",
        TypeID     => $VertexTypeID,
        Properties => {
            Key1 => "Value 1",
            Key2 => "Value 2"
        }
    }
});

if (!$VertexID) {
    $Log->Message('ERROR', "Error Creating VertexTree: $Message");
}

OR

my $VertexID = CreateVertexTree({
    DBH         => \$DBH,
    NDB         => \$NDB,
    StorageHash => $StorageHash,
    VertexTree  => {
        Name       => "Vertex 1",
        TypeID     => $VertexTypeID,
        Properties => {
            Key1 => "Value 1",
            Key2 => "Value 2"
        }
    }
});

if (!$VertexID) {
    $Log->Message('ERROR', "Error Creating VertexTree");
}

CypherQuote

Determines whether a given value is a number or string, adding necessary "quotes" or escapes chars where applicable

CypherQuote(\%options)

Options

value    -> The value to examine

Returns

value    -> The modified value, including any necessary escape chars or "quotes"

DeleteEdgeID

Delete Edge.

DeleteEdgeID(\%options)

Options

NDB         -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash -> (Recommended) Cache (i.e. $StorageHash)
EdgeID      -> Edge to delete
EdgeType    -> (Optional) Edge Type
VertexType1 -> (Optional) Start Vertex Type
VertexType1 -> (Optional) End Vertex Type

Returns

1. ErrorFlag   (0 Good, 1 Bad)
2. Message     (String)

Synopsis

DeleteEdgeID({
    NDB         => \$NDB,
    StorageHash => $StorageHash,
    EdgeID      => $EdgeID
});

DeleteVertexID

Delete Vertex ID.

DeleteVertexID(\%options)

Options

NDB         -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash -> (Recommended) Cache (i.e. $StorageHash)
VertexID    -> Vertex to delete
VertexType  -> (Optional) Vertex Type

Returns

1. ErrorFlag   (0 Good, 1 Bad)
2. Message     (String)

Synopsis

DeleteVertexID({
    NDB         => \$NDB,
    StorageHash => $StorageHash,
    VertexID    => $VertexID
});

ExecuteCypherQuery

Runs a Cypher query on a Neo4j database

ExecuteCypherQuery(\%options)

Options

NDB         -> Neo4j Database Handle Reference (i.e. \$NDB)
CypherQuery -> The Cypher query to run

Returns

Error        The error message returned from Neo4j, if an error has occurred (undef if query is successful)
Results      The query result, as an array of rows

FindEdgeID

Finds an edge by the vertices and Type and returns ID if found. If Create option set to true (1), will create edge automatically if not found.

FindEdgeID(\%options)

Options

NDB         -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash -> Cache (i.e. $StorageHash)
VertexID1   -> Start of Edge
VertexType1 -> (Optional) Vertex Type
VertexID2   -> End of Edge
VertexType2 -> (Optional) Vertex Type
TypeID      -> Edge Type ID
EdgeType    -> (Optional) Edge Type
Create      -> (Optional) Create Flag (0=don't create if not found, 1=create if not found)

Returns

1. ErrorFlag (0 Good, 1 Bad)
2. Message   (String)
3. Edge ID   (String) or undef if not found/created

Synopsis

my ($ErrorFlag, $Message, $EdgeID) = FindEdgeID({
    NDB         => \$NDB,
    StorageHash => $StorageHash,
    VertexID1   => $VertexID1,
    VertexID2   => $VertexID2,
    TypeID      => $EdgeTypeID,
    Create      => 1
});

if (!$EdgeID) {
    $Log->Message('ERROR', "Error Finding Edge: $Message");
}

OR

my $EdgeID = FindEdgeID({
    NDB         => \$NDB,
    StorageHash => $StorageHash,
    VertexID1   => $VertexID1,
    VertexID2   => $VertexID2,
    TypeID      => $EdgeTypeID,
    Create      => 1
});

if (!$EdgeID) {
    $Log->Message('ERROR', "Error Finding Edge");
}

FindEdgeProperty

Retrieves an Edge property and returns the value. If Create option set to true (1), will create/update the property with the given value instead.

FindEdgeProperty(\%options)

Options

NDB         -> Neo4j Database Handle Reference (i.e. \$NDB).
EdgeID      -> Edge ID for properties
EdgeType    -> (Optional) Edge Type
VertexType1 -> (Optional) Start Vertex Type
VertexType2 -> (Optional) End Vertex Type
Name        -> Property Name
Value       -> (Optional) Property Value
Create      -> (Optional) Create Flag (0=don't create if not found, 1=create if not found)

Returns

1. ErrorFlag   (0 Good, 1 Bad)
2. Message     (String)
3. Property Value or undef if not created/updated

Synopsis

Set:

my ($ErrorFlag, $Message) = FindEdgeProperty({
    NDB     => \$NDB,
    EdgeID  => $EdgeID,
    Name    => "Key",
    Value   => "Value",
    Create  => 1
});

if ($ErrorFlag) {
    $Log->Message('ERROR', "Error Setting Edge Property: $Message");
}

Get:

my ($ErrorFlag, $Message, $Value) = FindEdgeProperty({
    NDB     => \$NDB,
    EdgeID  => $EdgeID,
    Name    => "Key"
});

if ($ErrorFlag) {
    $Log->Message('ERROR', "Error Getting Edge Property: $Message");
}

FindEdgeTypeName

Find Edge type Name by Type ID

FindEdgeTypeName(\%options)

Options

NDB          -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash  -> Cache (i.e. $StorageHash)
TypeID       -> Edge Type ID

Returns

1. ErrorFlag      (0 Good, 1 Bad)
2. Message        (String)
3. Edge Type name (String) or undef if not created

Synopsis

my ($ErrorFlag, $Message, $EdgeTypeName) = FindEdgeTypeName({
    NDB          => \$NDB,
    StorageHash  => $StorageHash,
    TypeID       => $EdgeTypeID
});

if (!$EdgeTypeName) {
    $Log->Message('ERROR', "Error Finding Edge Type: $Message");
}

OR

my $EdgeTypeName = FindEdgeTypeName({
    NDB          => \$NDB,
    StorageHash  => $StorageHash,
    TypeID       => $EdgeTypeID
});

if (!$EdgeTypeName) {
    $Log->Message('ERROR', "Error Finding Edge Type");
}

FindEdgeTypeID

Find Edge type by Name, LineStyle, Direction. If Create option set to true (1), will create Edge type automatically if not found.

FindEdgeTypeID(\%options)

Options

NDB          -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash  -> Cache (i.e. $StorageHash)
Name         -> Edge Type Name
LineStyle    -> "Solid", "Dashed" or "Dotted"
Direction    -> Edge data direction (0=Non-Directed, 1=Directed)
Create       -> (Optional) Create Flag (0=don't create if not found, 1=create if not found)

Returns

1. ErrorFlag    (0 Good, 1 Bad)
2. Message      (String)
3. Edge Type ID (Integer) or undef if not created/updated

Synopsis

my ($ErrorFlag, $Message, $EdgeTypeID) = FindEdgeTypeID({
    NDB          => \$NDB,
    StorageHash  => $StorageHash,
    Name         => "My Edge Type",
    LineStyle    => "Solid",
    Direction    => 0,
    Create       => 1
});

if (!$EdgeTypeID) {
    $Log->Message('ERROR', "Error Finding Edge Type: $Message");
}

OR

my $EdgeTypeID = FindEdgeTypeID({
    NDB          => \$NDB,
    StorageHash  => $StorageHash,
    Name         => "My Edge Type",
    LineStyle    => "Solid",
    Direction    => 0,
    Create       => 1
});

if (!$EdgeTypeID) {
    $Log->Message('ERROR', "Error Finding Edge Type");
}

FindVertexByDevice

Finds a Vertex ID by device arguments (DeviceID, DNS name, IP address etc). If Create option is set to true (1), will create the vertex and return the ID.

FindVertexByDevice(\%options)

Options

DBH          -> Unified Assurance Database Handle Reference (i.e. \$DBH)
NDB          -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash  -> Cache (i.e. $StorageHash)
DNS          -> DNS for lookup
IP           -> IPv4 address for lookup
IPv6         -> IPv6 address for lookup
CustomName   -> Custom Name for lookup
Create       -> (Optional) Create Flag
VertexName   -> VertexName to use with create

Returns

1. ErrorFlag (0 Good, 1 Bad)
2. Message   (String)
3. Vertex ID (String)

Synopsis

my ($ErrorFlag, $Message, $Vertex) = FindVertexByDevice({
   DBH          => \$DBH,
   NDB          => \$NDB,
   StorageHash  => $StorageHash,
   DNS          => "<DNSNAME>",
   IP           => "<IPADDRESS>",
   CustomName   => "<CUSTOMNAME>",
   VertexName   => "<VERTEXNAME>",
   Create       => 1,
});

FindVertexID

Finds a Vertex by the Name and Type and returns the ID of the Vertex if found. Searches only ParentID node's direct children. If Create option set to true (1), will create the vertex automatically (but not link it) if not found.

FindVertexID(\%options)

Options

DBH         -> Unified Assurance Database Handle Reference (i.e. \$DBH)
NDB         -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash -> Cache (i.e. $StorageHash)
Name        -> Vertex Name
TypeID      -> Vertex Type
ParentID    -> (Optional) Vertex ParentID (-1=any (first occurrence), 0=top-level. Defaults to -1)
Create      -> (Optional) Create Flag (0=don't create if not found, 1=create if not found. Defaults to 0)

Returns

1. ErrorFlag   (0 Good, 1 Bad)
2. Message     (String)
3. Vertex ID   (String) or undef if not found/created

Synopsis

my ($ErrorFlag, $Message, $VertexID) = FindVertexID({
    DBH         => \$DBH,
    NDB         => \$NDB,
    StorageHash => $StorageHash,
    Name        => "<VERTEXNAME>",
    TypeID      => $VertexTypeID,
    Create      => 1
});

if (!$VertexID) {
   $Log->Message('ERROR', "Error Finding Vertex: $Message");
}

OR

my $VertexID = FindVertexID({
   DBH         => \$DBH,
   NDB         => \$NDB,
   StorageHash => $StorageHash,
   Name        => "<VERTEXNAME>",
   TypeID      => $VertexTypeID,
   Create      => 1
});

if (!$VertexID) {
   $Log->Message('ERROR', "Error Finding Vertex");
}

FindLinkedVertices

Finds directly linked parents by the VertexID and EdgeType and returns a list containing a hash of each linked vertex.

FindLinkedVertices(\%options)

Options

NDB         -> Neo4j Database Handle Reference (i.e. \$NDB).
VertexID    -> VertexID
Direction   -> (Optional) Edge data direction. (0=Non-Directed, 1=Direct Parents, 2=Direct Children) defaults to 1. Non-Directed returns list of any neighbors (parent or child), Direct Parent returns list of parents and Direct Children returns list of children.
TypeID      -> (Optional) Searches for neighbors/parents of a certain Vertex Type. If not given, searches for any vertex type.
VertexType  -> (Optional) Vertex Type. If TypeID is specified, TypeID will take precedence. If not given, searches for any vertex type.
EdgeTypeID  -> (Optional) Looks for neighbors/parents linked with the given Edge Type ID. If not given, searches for any edge type.
EdgeType    -> (Optional) Edge Type. If EdgeTypeID is specified, EdgeTypeID will take precedence. If not given, searches for any edge type.

Returns

1. ErrorFlag    (0 Good, 1 Bad)
2. Message      (String)
3. Parent Links (Array ref) or undef if error. Contains list of linked vertex info:
   * VertexID

Synopsis

my ($ErrorFlag, $Message, $Parents) = FindLinkedVertices({
    NDB         => \$NDB,
    VertexID    => $VertexID,
    Direction   => 1
});

if ($ErrorFlag) {
   $Log->Message('ERROR', "Error Finding Parents: $Message");
}

OR

my $Parents = FindLinkedVertices({
    NDB         => \$NDB,
    VertexID    => $VertexID,
    Direction   => 1
});

if (!$Parents) {
   $Log->Message('ERROR', "Error Finding Parents");
}

FindVertexProperty

Retrieves a Vertex property and returns the value. If Create option set to true (1), will create/update the property with the given value instead.

FindVertexProperty(\%options)

Options

NDB         -> Neo4j Database Handle Reference (i.e. \$NDB).
VertexID    -> Vertex ID for properties
VertexType  -> (Optional) Vertex Type
Name        -> Property Name
Value       -> (Optional) Property Value
Create      -> (Optional) Create Flag (0=don't create if not found, 1=create if not found)
StorageHash -> Cache (i.e. $StorageHash)

Returns

1. ErrorFlag   (0 Good, 1 Bad)
2. Message     (String)
3. Property Value or undef if not created/updated

Synopsis

Set:

my ($ErrorFlag, $Message) = FindVertexProperty({
    NDB       => \$NDB,
    VertexID  => $VertexID,
    Name      => "Key",
    Value     => "Value",
    Create    => 1
});

if ($ErrorFlag) {
    $Log->Message('ERROR', "Error Setting Vertex Property: $Message");
}

Get:

my ($ErrorFlag, $Message, $Value) = FindVertexProperty({
    NDB       => \$NDB,
    VertexID  => $VertexID,
    Name      => "Key"
});

if ($ErrorFlag) {
    $Log->Message('ERROR', "Error Getting Vertex Property: $Message");
}

FindVertexTypeID

Find vertex type by Name and icon path. If Create option set to true (1), will create vertex type automatically if not found.

FindVertexTypeID(\%options)

Options

NDB         -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash -> Cache (i.e. $StorageHash)
Name        -> Vertex Type Name
IconPath    -> Vertex Icon path (relative to the icons directory)

Returns

1. ErrorFlag      (0 Good, 1 Bad)
2. Message        (String)
3. Vertex Type ID (Integer) or undef if not created

Synopsis

my ($ErrorFlag, $Message, $VertexTypeID) = FindVertexTypeID({
    NDB         => \$NDB,
    StorageHash => $StorageHash,
    Name        => "<VERTEXTYPENAME>",
    IconPath    => "/images/Info.png"
    Create      => 1
});

if (!$VertexTypeID) {
    $Log->Message('ERROR', "Error Finding Vertex Type: $Message");
}

OR

my $VertexTypeID = FindVertexTypeID({
    NDB         => \$NDB,
    StorageHash => $StorageHash,
    Name        => "<VERTEXTYPENAME>",
    IconPath    => "/images/Info.png"
    Create      => 1
});

if (!$VertexTypeID) {
    $Log->Message('ERROR', "Error Finding Vertex Type");
}

FindVertexTypeName

Find vertex type name by vertex type ID

FindVertexTypeName(\%options)

Options

NDB          -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash  -> Cache (i.e. $StorageHash)
TypeID       -> Vertex Type ID

Returns

1. ErrorFlag    (0 Good, 1 Bad)
2. Message      (String)
3. Vertex type name (String) or undef if not created

Synopsis

my ($ErrorFlag, $Message, $VertexTypeName) = FindVertexTypeName({
    NDB          => \$NDB,
    StorageHash  => $StorageHash,
    TypeID       => VertexTypeID
});

if (!$VertexTypeName) {
    $Log->Message('ERROR', "Error Finding Vertex Type: $Message");
}

OR

my $VertexTypeName = FindVertexTypeName({
    NDB          => \$NDB,
    StorageHash  => $StorageHash,
    TypeID       => VertexTypeID
});

if (!$VertexTypeName) {
    $Log->Message('ERROR', "Error Finding Vertex Type");
}

GetNDBConnection

Open a connection to Neo4j. If $NDB is already defined, simply returns $NDB. Otherwise, attempts to establish a new connection.

GetNDBConnection(\%options)

Options

NDB      -> Neo4j Database Handle Reference (i.e. \$NDB).
Expire   -> Expire time for JWT token. Defaults to 3600 seconds (1 hour)

Returns

NDB      Neo4j Database Handle Reference

GetVertexInfo

Obtain a Vertex's information such as Name, Vertex Type, and Properties.

GetVertexInfo(\%options)

Options

NDB         -> Neo4j Database Handle Reference (i.e. \$NDB).
StorageHash -> Cache (i.e. $StorageHash)
VertexID    -> Vertex ID
VertexType  -> (Optional) Vertex Type

Returns

1. ErrorFlag      (0 Good, 1 Bad)
2. Message        (String)
3. Vertex Info (Hash ref) or undef if not found

Synopsis

my ($ErrorFlag, $Message, $VertexInfo) = GetVertexInfo({
    NDB         => \$NDB,
    StorageHash => $StorageHash,
    VertexID    => $VertexID
});

if ($ErrorFlag) {
    $Log->Message('ERROR', "Error Finding Vertex Info: $Message");
}

OR

my $VertexInfo = GetVertexInfo({
    NDB         => \$NDB,
    StorageHash => $StorageHash,
    VertexID    => $VertexID
});

if (!$VertexInfo) {
    $Log->Message('ERROR', "Error Finding Vertex Info");
}