Assure1::Graph Perl library
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
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
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({
ODB => \$ODB,
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");
}
CloneObjectID
Deprecated
Backward compatibility function for "CloneVertexID".
CreateEdgeTree
Convenience function to create an Edge Tree with Properties all at once.
CreateEdgeTree(\%options)
Options
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
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({
ODB => \$ODB,
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");
}
CreateLinkTree
Deprecated
Backward compatibility function for "CreateEdgeTree".
CreateVertexTree
Convenience function to create vertex tree with properties all at once.
CreateVertexTree(\%options)
Options
DBH -> Unified Assurance Database Handle Reference (i.e. \$DBH)
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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,
ODB => \$ODB,
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,
ODB => \$ODB,
StorageHash => $StorageHash,
VertexTree => {
Name => "Vertex 1",
TypeID => $VertexTypeID,
Properties => {
Key1 => "Value 1",
Key2 => "Value 2"
}
}
});
if (!$VertexID) {
$Log->Message('ERROR', "Error Creating VertexTree");
}
CreateObjectTree
Deprecated
Backward compatibility function for "CreateVertexTree".
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
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
StorageHash => $StorageHash,
EdgeID => $EdgeID
});
DeleteLinkID
Deprecated
Backward compatibility function for "DeleteEdgeID".
DeleteVertexID
Delete Vertex ID.
DeleteVertexID(\%options)
Options
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
StorageHash => $StorageHash,
VertexID => $VertexID
});
DeleteObjectID
Deprecated
Backward compatibility function for "DeleteVertexID".
ExecuteCypherQuery
Executes a Cypher query on a Neo4j database
ExecuteCypherQuery(\%options)
Options
NDB -> Neo4j Database Handle Reference (i.e. \$NDB)
CypherQuery -> The Cypher query to execute
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
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
StorageHash => $StorageHash,
VertexID1 => $VertexID1,
VertexID2 => $VertexID2,
TypeID => $EdgeTypeID,
Create => 1
});
if (!$EdgeID) {
$Log->Message('ERROR', "Error Finding Edge: $Message");
}
OR
my $EdgeID = FindEdgeID({
ODB => \$ODB,
StorageHash => $StorageHash,
VertexID1 => $VertexID1,
VertexID2 => $VertexID2,
TypeID => $EdgeTypeID,
Create => 1
});
if (!$EdgeID) {
$Log->Message('ERROR', "Error Finding Edge");
}
FindLinkID
Deprecated
Backward compatibility function for "FindEdgeID".
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
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
EdgeID => $EdgeID,
Name => "Key",
Value => "Value",
Create => 1
});
if ($ErrorFlag) {
$Log->Message('ERROR', "Error Setting Edge Property: $Message");
}
Get:
my ($ErrorFlag, $Message, $Value) = FindEdgeProperty({
ODB => \$ODB,
EdgeID => $EdgeID,
Name => "Key"
});
if ($ErrorFlag) {
$Log->Message('ERROR', "Error Getting Edge Property: $Message");
}
FindLinkProperty
Deprecated
Backward compatibility function for "FindEdgeProperty".
FindEdgeTypeName
Find Edge type Name by Type ID
FindEdgeTypeName(\%options)
Options
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
StorageHash => $StorageHash,
TypeID => $EdgeTypeID
});
if (!$EdgeTypeName) {
$Log->Message('ERROR', "Error Finding Edge Type: $Message");
}
OR
my $EdgeTypeName = FindEdgeTypeName({
ODB => \$ODB,
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
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
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({
ODB => \$ODB,
StorageHash => $StorageHash,
Name => "My Edge Type",
LineStyle => "Solid",
Direction => 0,
Create => 1
});
if (!$EdgeTypeID) {
$Log->Message('ERROR', "Error Finding Edge Type");
}
FindLinkTypeID
Deprecated
Alias function for "FindEdgeTypeID".
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)
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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,
ODB => \$ODB,
StorageHash => $StorageHash,
DNS => "somehost.com",
IP => "1.2.3.4",
CustomName => "Some Host",
VertexName => "Test_VertexName",
Create => 1,
});
FindObjectByDevice
Deprecated
Backward compatibility function for "FindVertexByDevice".
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)
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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,
ODB => \$ODB,
StorageHash => $StorageHash,
Name => "My Vertex",
TypeID => $VertexTypeID,
Create => 1
});
if (!$VertexID) {
$Log->Message('ERROR', "Error Finding Vertex: $Message");
}
OR
my $VertexID = FindVertexID({
DBH => \$DBH,
ODB => \$ODB,
StorageHash => $StorageHash,
Name => "My Vertex",
TypeID => $VertexTypeID,
Create => 1
});
if (!$VertexID) {
$Log->Message('ERROR', "Error Finding Vertex");
}
FindObjectID
Deprecated
Alias function for "FindVertexID".
FindLinkedVertices
Finds directly linked parents by the VertexID and EdgeType and returns a list containing a hash of each linked vertex.
FindLinkedVertices(\%options)
Options
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
VertexID => $VertexID,
Direction => 1
});
if ($ErrorFlag) {
$Log->Message('ERROR', "Error Finding Parents: $Message");
}
OR
my $Parents = FindLinkedVertices({
ODB => \$ODB,
VertexID => $VertexID,
Direction => 1
});
if (!$Parents) {
$Log->Message('ERROR', "Error Finding Parents");
}
FindLinkedObjects
Deprecated
Backward compatibility function for "FindLinkedVertices".
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
ODB -> OrientDB Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
VertexID => $VertexID,
Name => "Key",
Value => "Value",
Create => 1
});
if ($ErrorFlag) {
$Log->Message('ERROR', "Error Setting Vertex Property: $Message");
}
Get:
my ($ErrorFlag, $Message, $Value) = FindVertexProperty({
ODB => \$ODB,
VertexID => $VertexID,
Name => "Key"
});
if ($ErrorFlag) {
$Log->Message('ERROR', "Error Getting Vertex Property: $Message");
}
FindObjectProperty
Deprecated
Backward compatibility function for "FindVertexProperty".
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
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
StorageHash => $StorageHash,
Name => "My Vertex Type",
IconPath => "/images/Info.png"
Create => 1
});
if (!$VertexTypeID) {
$Log->Message('ERROR', "Error Finding Vertex Type: $Message");
}
OR
my $VertexTypeID = FindVertexTypeID({
ODB => \$ODB,
StorageHash => $StorageHash,
Name => "My Vertex Type",
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
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
StorageHash => $StorageHash,
TypeID => VertexTypeID
});
if (!$VertexTypeName) {
$Log->Message('ERROR', "Error Finding Vertex Type: $Message");
}
OR
my $VertexTypeName = FindVertexTypeName({
ODB => \$ODB,
StorageHash => $StorageHash,
TypeID => VertexTypeID
});
if (!$VertexTypeName) {
$Log->Message('ERROR', "Error Finding Vertex Type");
}
FindObjectTypeID
Deprecated
Alias function for "FindVertexTypeID".
GetGraphDBType
Determine which Graph database is enabled.
GetGraphDBType()
Returns
GraphDBType ("OrientDB" or "Neo4j")
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
GetObjectInfo
Deprecated
Backward compatibility function for "GetVertexInfo".
GetVertexInfo
Obtain a Vertex's information such as Name, Vertex Type, and Properties.
GetVertexInfo(\%options)
Options
ODB -> Orient Database Handle Reference (i.e. \$ODB). Use if OrientDB is enabled.
NDB -> Neo4j Database Handle Reference (i.e. \$NDB). Use if Neo4j is enabled.
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({
ODB => \$ODB,
StorageHash => $StorageHash,
VertexID => $VertexID
});
if ($ErrorFlag) {
$Log->Message('ERROR', "Error Finding Vertex Info: $Message");
}
OR
my $VertexInfo = GetVertexInfo({
ODB => \$ODB,
StorageHash => $StorageHash,
VertexID => $VertexID
});
if (!$VertexInfo) {
$Log->Message('ERROR', "Error Finding Vertex Info");
}