来自 CSV 文件的图表的 arangoimp

arangoimp of graph from CSV file

我在 TSV 文件中进行了网络扫描,该文件包含如下示例形式的数据

source IP      target IP       source port    target port
192.168.84.3   192.189.42.52   5868           1214
192.168.42.52  192.189.42.19   1214           5968
192.168.4.3    192.189.42.52   60680          22
....  
192.189.42.52  192.168.4.3     22             61969

有没有一种简单的方法可以使用 arangoimp 将其导入到(预先创建的)边缘收集网络数据中?

您可以合并 the TSV importer, if it wouldn't fail converting the IPs (fixed in ArangoDB 3.0), so you need a bit more conversion logic to get valid CSV. One will use the ede attribute conversion option 以在导入期间将前两列转换为有效的 _from_to 属性。

您不应指定其中包含空格的列主题,它实际上应该是制表符或固定数量的列。我们需要在主题行中指定 _from_to 字段。

为了使其正常工作,您可以通过 sed 将上述内容通过管道传输以获得有效的 CSV 和正确的列名称,如下所示:

cat /tmp/test.tsv  | \
  sed -e "s;source IP;_from;g;" \
      -e "s;target IP;_to;" \
      -e "s; port;Port;g" \
      -e 's;  *;",";g' \
      -e 's;^;";' \
      -e 's;$;";' | \
   arangoimp --file - \
      --type csv \
      --from-collection-prefix sourceHosts \
      --to-collection-prefix targetHosts \
      --collection "ipEdges" \
      --create-collection true \
      --create-collection-type edge

使用这些正则表达式的 Sed 将创建一个如下所示的中间表示:

"_from","_to","sourcePort","targetPort"
"192.168.84.3","192.189.42.52","5868","1214"

生成的边看起来像这样:

{ 
  "_key" : "21056", 
  "_id" : "ipEdges/21056", 
  "_from" : "sourceHosts/192.168.84.3", 
  "_to" : "targetHosts/192.189.42.52", 
  "_rev" : "21056", 
  "sourcePort" : "5868", 
  "targetPort" : "1214" 
}