Mini graph app

Network Management

Cascading dependencies

An enterprise network is a graph of equipment and applications.

This guide will show you how to:

  1. Create: insert records for network components
  2. Find: retrieve individual components
  3. Query: discover dependency relationships
  4. Solve: impact analysis
Network Management

Create

To the right is a code block containing a single Cypher query statement composed of multiple CREATE clauses. This will create the network graph.

  1. Click on the code
  2. Notice it gets copied to the editor above ↑
  3. Click the editor's play button to exectute
  4. Wait for the query to finish

WARNING: This adds data to the current database, each time it is run!


:help cypher CREATE

CREATE (crm:Application {
      application: "CRM",
      ip:'10.10.32.1',
      host:'crm-host'
})
CREATE (erp:Application {
      application: "ERP",
      ip:'10.10.33.1',
      host:'erp-host'
})
CREATE (datawarehouse:DataWarehouse {
      ip:'10.10.34.1',
      host:'datawarehouse-host'
})
CREATE (publicwebsite1:PublicWebsite {
      ip:'10.10.35.1',
      host:'global.acme.com'
})
CREATE (publicwebsite2:PublicWebsite {
      ip:'10.10.35.2',
      host:'support.acme.com'
})
CREATE (publicwebsite3:PublicWebsite {
      ip:'10.10.35.3',
      host:'shop.acme.com'
})
CREATE (publicwebsite4:PublicWebsite {
      ip:'10.10.35.4',
      host:'training.acme.com'
})
CREATE (publicwebsite5:PublicWebsite {
      ip:'10.10.35.1',
      host:'partners.acme.com'
})
CREATE (internalwebsite1:InternalWebsite {
      ip:'10.10.35.2',
      host:'events.acme.net'
})
CREATE (internalwebsite2:InternalWebsite {
      ip:'10.10.35.3',
      host:'intranet.acme.net'
})
CREATE (internalwebsite3:InternalWebsite {
      ip:'10.10.35.4',
      host:'humanresources.acme.net'
})
CREATE (webservervm1:WebserverVM {
      ip:'10.10.35.5',
      host:'webserver1-vm-host'
})
CREATE (webservervm2:WebserverVM {
      ip:'10.10.35.6',
      host:'webserver2-vm-host'
})
CREATE (databasevm1:CustomerDatabase {
      ip:'10.10.35.7',
      host:'customerdatabase1-host'
})
CREATE (databasevm2:CustomerDatabase {
      ip:'10.10.35.8',
      host:'customerdatabase2-host'
})
CREATE (databasevm3:DatabaseVM {
      ip:'10.10.35.9',
      host:'erpdatabase-host'
})
CREATE (databasevm4:DWDatabase {
      ip:'10.10.35.10',
      host:'dwdatabase-host'
})
CREATE (hardware1:Hardware {
      ip:'10.10.35.11',
      host:'hardware1-host'
})
CREATE (hardware2:Hardware {
      ip:'10.10.35.12',
      host:'hardware2-host'
})
CREATE (hardware3:Hardware {
      ip:'10.10.35.13',
      host:'hardware3-host'
})
CREATE (san1:SAN {
      ip:'10.10.35.14',
      host:'san-host'
})

CREATE (crm)-[:DEPENDS_ON]->(databasevm1)

CREATE  (publicwebsite1)-[:DEPENDS_ON]->(databasevm1),
      (publicwebsite2)-[:DEPENDS_ON]->(databasevm1),
      (publicwebsite3)-[:DEPENDS_ON]->(databasevm1)
      
CREATE  (databasevm1)-[:DEPENDS_ON]->(hardware1)

CREATE  (hardware1)-[:DEPENDS_ON]->(san1)

CREATE  (webservervm1)<-[:DEPENDS_ON]-(publicwebsite1),
    (webservervm1)<-[:DEPENDS_ON]-(publicwebsite2),
    (webservervm1)<-[:DEPENDS_ON]-(publicwebsite3)
    
CREATE  (webservervm1)<-[:DEPENDS_ON]-(internalwebsite1),
    (webservervm1)<-[:DEPENDS_ON]-(internalwebsite2),
    (webservervm1)<-[:DEPENDS_ON]-(internalwebsite3)
    
CREATE  (webservervm1)-[:DEPENDS_ON]->(hardware2)

CREATE  (hardware2)-[:DEPENDS_ON]->(san1)

CREATE  (webservervm2)-[:DEPENDS_ON]->(hardware2)

CREATE  (webservervm2)<-[:DEPENDS_ON]-(publicwebsite4),
    (webservervm2)<-[:DEPENDS_ON]-(publicwebsite5)
    
CREATE  (hardware2)<-[:DEPENDS_ON]-(databasevm2)

CREATE  (publicwebsite4)-[:DEPENDS_ON]->(databasevm2),
      (publicwebsite5)-[:DEPENDS_ON]->(databasevm2)
      
CREATE  (hardware3)-[:DEPENDS_ON]->(san1)

CREATE  (hardware3)<-[:DEPENDS_ON]-(databasevm3)

CREATE  (erp)-[:DEPENDS_ON]->(databasevm3)

CREATE  (hardware3)<-[:DEPENDS_ON]-(databasevm4)

CREATE  (datawarehouse1)-[:DEPENDS_ON]->(databasevm4)

RETURN san1
Network Management

Find

Example queries for finding individual nodes.

  1. Click on any query example
  2. Run the query from the editor
  3. Notice the syntax pattern
  4. Try looking for other movies or actors

:help MATCH WHERE RETURN

Find the actor named "Tom Hanks"...

MATCH (tom {name: "Tom Hanks"}) RETURN tom

Find the movie with title "Cloud Atlas"...

MATCH (cloudAtlas {title: "Cloud Atlas"}) RETURN cloudAtlas

Find 10 people...

MATCH (people:Person) RETURN people.name LIMIT 10

Find movies released in the 1990s...

MATCH (nineties:Movie) WHERE nineties.released > 1990 AND nineties.released < 2000 RETURN nineties.title
Network Management

Query

Finding patterns within the graph.

  1. Actors are people who acted in movies
  2. Directors are people who directed a movie
  3. What other relationships exist?

:help MATCH

List all Tom Hanks movies...

MATCH (tom:Person {name: "Tom Hanks"})-[:ACTED_IN]->(tomHanksMovies) RETURN tom,tomHanksMovies

Who directed "Cloud Atlas"?

MATCH (cloudAtlas {title: "Cloud Atlas"})<-[:DIRECTED]-(directors) RETURN directors.name

Tom Hanks' co-actors...

MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors) RETURN coActors.name

How people are related to "Cloud Atlas"...

MATCH (people:Person)-[relatedTo]-(:Movie {title: "Cloud Atlas"}) RETURN people.name, Type(relatedTo), relatedTo
Network Management

Solve

You've heard of the classic "Six Degrees of Kevin Bacon"? That is simply a shortest path query called the "Bacon Path".

  1. Variable length patterns
  2. Built-in shortestPath() algorithm

Neo4j Manual

Movies and actors up to 4 "hops" away from Kevin Bacon

MATCH (bacon:Person {name:"Kevin Bacon"})-[*1..4]-(hollywood)
RETURN DISTINCT hollywood

Bacon path, the shortest path of any relationships to Meg Ryan

MATCH p=shortestPath(
  (bacon:Person {name:"Kevin Bacon"})-[*]-(meg:Person {name:"Meg Ryan"})
)
RETURN p
Network Management

Clean up

When you're done experimenting, you can remove the movie data set.

Note:

  1. Nodes can't be deleted if relationships exist
  2. Delete both nodes and relationships together

WARNING: This will remove all Person and Movie nodes!


:help DELETE

Delete all Movie and Person nodes, and their relationships

MATCH (a:Person),(m:Movie) OPTIONAL MATCH (a)-[r1]-(), (m)-[r2]-() DELETE a,r1,m,r2

Prove that the Movie Graph is gone

MATCH (n) RETURN n

Network Management


Next steps

Review getting started

Try more code