Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
C
CUREX
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alberto Blázquez Herranz
CUREX
Commits
12a79968
Commit
12a79968
authored
Nov 06, 2020
by
David Fernandez Lobon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sniffig snapshot unica
parent
a4abd56a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
7 deletions
+28
-7
src/main/java/adt/mainnode/repository/SnapshotRepository.java
...main/java/adt/mainnode/repository/SnapshotRepository.java
+1
-0
src/main/java/adt/mainnode/service/AssetService.java
src/main/java/adt/mainnode/service/AssetService.java
+27
-7
No files found.
src/main/java/adt/mainnode/repository/SnapshotRepository.java
View file @
12a79968
...
@@ -11,5 +11,6 @@ public interface SnapshotRepository extends JpaRepository<Snapshot, String> {
...
@@ -11,5 +11,6 @@ public interface SnapshotRepository extends JpaRepository<Snapshot, String> {
Snapshot
findBySnapshotId
(
String
snapshotId
);
Snapshot
findBySnapshotId
(
String
snapshotId
);
Snapshot
findTopByVlanNameOrderByTimestampDistNodeEndDesc
(
String
vlanName
);
Snapshot
findTopByVlanNameOrderByTimestampDistNodeEndDesc
(
String
vlanName
);
Snapshot
findTopByVlanNameAndDiscoveryMethodOrderByTimestampDistNodeEndDesc
(
String
vlanName
,
String
discoveryMethod
);
}
}
src/main/java/adt/mainnode/service/AssetService.java
View file @
12a79968
...
@@ -91,9 +91,27 @@ public class AssetService {
...
@@ -91,9 +91,27 @@ public class AssetService {
List
<
ScanInfoDto
>
allScans
=
asset
.
getScanInfo
();
List
<
ScanInfoDto
>
allScans
=
asset
.
getScanInfo
();
boolean
nueva_snapshot
=
true
;
String
generatedHash
=
null
;
Snapshot
snapshot
=
null
;
if
(
asset
.
getDiscoveryMethod
().
equals
(
"sniffing"
)){
Snapshot
snapshot_scan
=
snapshotRepository
.
findTopByVlanNameAndDiscoveryMethodOrderByTimestampDistNodeEndDesc
(
allScans
.
get
(
0
).
getVlanName
(),
"scan"
);
Snapshot
snapshot_sniffing
=
snapshotRepository
.
findTopByVlanNameAndDiscoveryMethodOrderByTimestampDistNodeEndDesc
(
allScans
.
get
(
0
).
getVlanName
(),
"sniffing"
);
if
(
snapshot_scan
!=
null
&&
snapshot_sniffing
!=
null
&&
snapshot_scan
.
getTimestamp_mainNode
().
getTime
()
<
snapshot_sniffing
.
getTimestamp_mainNode
().
getTime
()
){
// Utilizas la snapshot_sniffing que ya tienes y la actualizas
generatedHash
=
snapshot_sniffing
.
getSnapshotId
();
nueva_snapshot
=
false
;
snapshot
=
snapshot_sniffing
;
}
}
Date
mainNode_timestamp
=
new
Date
();
Date
mainNode_timestamp
=
new
Date
();
String
generatedHash
=
DigestUtils
.
sha256Hex
(
DigestUtils
.
sha256Hex
(
mainNode_timestamp
.
toString
())
+
DigestUtils
.
sha256Hex
(
allScans
.
get
(
0
).
getIniTimestampScan
().
toString
())
+
DigestUtils
.
sha256Hex
(
allScans
.
get
(
0
).
getEndTimestampScan
().
toString
())
+
System
.
currentTimeMillis
());
if
(
nueva_snapshot
)
{
generatedHash
=
DigestUtils
.
sha256Hex
(
DigestUtils
.
sha256Hex
(
mainNode_timestamp
.
toString
())
+
DigestUtils
.
sha256Hex
(
allScans
.
get
(
0
).
getIniTimestampScan
().
toString
())
+
DigestUtils
.
sha256Hex
(
allScans
.
get
(
0
).
getEndTimestampScan
().
toString
())
+
System
.
currentTimeMillis
());
}
SnapshotChange
snapChange
=
evaluateChanges
(
allScans
,
mainNode_timestamp
,
asset
.
getDiscoveryMethod
());
SnapshotChange
snapChange
=
evaluateChanges
(
allScans
,
mainNode_timestamp
,
asset
.
getDiscoveryMethod
());
// TODO: retrieve from web form instead of hard-coding it here
// TODO: retrieve from web form instead of hard-coding it here
...
@@ -118,7 +136,7 @@ public class AssetService {
...
@@ -118,7 +136,7 @@ public class AssetService {
Node
node
=
nodeRepository
.
findByNodeId
(
credential
.
getName
());
Node
node
=
nodeRepository
.
findByNodeId
(
credential
.
getName
());
log
.
info
(
"let me {}"
,
scanInfo
);
log
.
info
(
"let me {}"
,
scanInfo
);
SnapshotIdentity
snapshotIdentity
=
SnapshotIdentity
.
createSnapshotIdentity
(
scanInfo
.
getVlanName
(),
node
.
getNodeId
(),
scanInfo
.
getSnapshotId
());
SnapshotIdentity
snapshotIdentity
=
SnapshotIdentity
.
createSnapshotIdentity
(
scanInfo
.
getVlanName
(),
node
.
getNodeId
(),
scanInfo
.
getSnapshotId
());
Snapshot
snapshot
=
Snapshot
.
createSnapshot
(
scanInfo
,
snapshotIdentity
,
asset
.
getDiscoveryMethod
());
if
(
nueva_snapshot
)
snapshot
=
Snapshot
.
createSnapshot
(
scanInfo
,
snapshotIdentity
,
asset
.
getDiscoveryMethod
());
//////
//////
// CREATING HOST AND PORT ENTITIES FROM THE RECEIVED DTO
// CREATING HOST AND PORT ENTITIES FROM THE RECEIVED DTO
...
@@ -132,9 +150,10 @@ public class AssetService {
...
@@ -132,9 +150,10 @@ public class AssetService {
hosts
.
add
(
host
);
hosts
.
add
(
host
);
String
finalGeneratedHash
=
generatedHash
;
List
<
Port
>
ports
=
host_dtos
.
get
(
i
).
getPorts
().
parallelStream
()
List
<
Port
>
ports
=
host_dtos
.
get
(
i
).
getPorts
().
parallelStream
()
.
map
(
portDto
->
{
.
map
(
portDto
->
{
PortIdentity
portIdentity
=
PortIdentity
.
createPortIdentity
(
portDto
.
getPortNumber
(),
host
.
getIp
(),
host
.
getVlanName
(),
g
eneratedHash
);
PortIdentity
portIdentity
=
PortIdentity
.
createPortIdentity
(
portDto
.
getPortNumber
(),
host
.
getIp
(),
host
.
getVlanName
(),
finalG
eneratedHash
);
return
Port
.
createPort
(
portIdentity
,
portDto
);
return
Port
.
createPort
(
portIdentity
,
portDto
);
})
})
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
...
@@ -144,8 +163,9 @@ public class AssetService {
...
@@ -144,8 +163,9 @@ public class AssetService {
}
}
//////
//////
if
(
nueva_snapshot
)
{
snapshotRepository
.
save
(
snapshot
);
snapshotRepository
.
save
(
snapshot
);
}
scanInfoRepository
.
save
(
scanInfo
);
scanInfoRepository
.
save
(
scanInfo
);
// WRITING SCAN INFO ENTITY TO FILE FOR ITS POSTERIOR UPLOAD TO VIRTUOSO'S DB
// WRITING SCAN INFO ENTITY TO FILE FOR ITS POSTERIOR UPLOAD TO VIRTUOSO'S DB
...
@@ -189,9 +209,9 @@ public class AssetService {
...
@@ -189,9 +209,9 @@ public class AssetService {
t
.
printStackTrace
();
t
.
printStackTrace
();
}
}
//////
//////
}
// End of initial for
}
// End of initial for
}
// End of method
}
// End of method
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment