Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
FMS_Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
bashar.hussein
FMS_Project
Commits
c5b76f65
Commit
c5b76f65
authored
Aug 09, 2023
by
ReemyHasan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add statistics functions
parent
4357b7ba
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
159 additions
and
4 deletions
+159
-4
RethinkController.java
.../example/WebApplication/controller/RethinkController.java
+74
-0
RethinkDBConnectionFactory.java
...le/WebApplication/factory/RethinkDBConnectionFactory.java
+3
-4
RethinkDBService.java
...com/example/WebApplication/services/RethinkDBService.java
+51
-0
UserController.java
...a/com/example/userService/controllers/UserController.java
+18
-0
UserCredentialRepository.java
...mple/userService/repository/UserCredentialRepository.java
+6
-0
UserService.java
...ain/java/com/example/userService/service/UserService.java
+7
-0
No files found.
SNMP_Pipeline/Web-Application/src/main/java/com/example/WebApplication/controller/RethinkController.java
View file @
c5b76f65
...
...
@@ -11,6 +11,9 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.web.bind.annotation.*
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -33,4 +36,75 @@ public class RethinkController {
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
}
}
@GetMapping
(
"/severity-statistics"
)
public
ResponseEntity
<
Map
<
String
,
Map
<
String
,
Integer
>>>
getSeverityStatistics
()
{
List
<
Map
<
String
,
Object
>>
rawResults
=
rethinkDBService
.
getData
();
if
(
rawResults
!=
null
)
{
Map
<
String
,
Map
<
String
,
Integer
>>
processedData
=
processRawResults
(
rawResults
);
return
ResponseEntity
.
ok
(
processedData
);
}
else
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
}
}
private
Map
<
String
,
Map
<
String
,
Integer
>>
processRawResults
(
List
<
Map
<
String
,
Object
>>
rawResults
)
{
Map
<
String
,
Map
<
String
,
Integer
>>
processedData
=
new
HashMap
<>();
for
(
Map
<
String
,
Object
>
rawEntry
:
rawResults
)
{
String
severityLevel
=
rawEntry
.
get
(
"severity"
).
toString
();
long
timestamp
=
(
long
)
rawEntry
.
get
(
"timestamp"
);
// Assuming timestamp is a long value representing Unix timestamp in milliseconds
// Convert Unix timestamp to a Date and extract hour
String
hour
=
convertTimestampToHour
(
timestamp
);
processedData
.
putIfAbsent
(
hour
,
new
HashMap
<>());
Map
<
String
,
Integer
>
hourMap
=
processedData
.
get
(
hour
);
hourMap
.
put
(
severityLevel
,
hourMap
.
getOrDefault
(
severityLevel
,
0
)
+
1
);
}
return
processedData
;
}
private
String
convertTimestampToHour
(
long
timestamp
)
{
Date
date
=
new
Date
(
timestamp
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
// Customize the format as needed
return
sdf
.
format
(
date
);
}
@GetMapping
(
"/getTrapCount"
)
public
long
getTrapCount
()
{
try
{
return
rethinkDBService
.
getTrapCount
();
}
catch
(
Exception
e
){
return
0
;
}
}
@GetMapping
(
"/getErrorTrapCount"
)
public
long
getErrorTrapCount
()
{
try
{
return
rethinkDBService
.
getErrorTrapCount
();
}
catch
(
Exception
e
){
return
0
;
}
}
@GetMapping
(
"/getWarningTrapCount"
)
public
long
getWarningTrapCount
()
{
try
{
return
rethinkDBService
.
getWarningTrapCount
();
}
catch
(
Exception
e
){
return
0
;
}
}
@GetMapping
(
"/getInfoTrapCount"
)
public
long
getInfoTrapCount
()
{
try
{
return
rethinkDBService
.
getInfoTrapCount
();
}
catch
(
Exception
e
){
return
0
;
}
}
}
SNMP_Pipeline/Web-Application/src/main/java/com/example/WebApplication/factory/RethinkDBConnectionFactory.java
View file @
c5b76f65
...
...
@@ -54,16 +54,15 @@ public class RethinkDBConnectionFactory {
if
(!
tables
.
contains
(
dbTableName
))
{
System
.
out
.
println
(
"Creating Table"
);
r
.
db
(
dbName
).
tableCreate
(
dbTableName
).
run
(
connection
);
//r.db(dbName).table(dbTableName).indexCreate("timestamp").run(connection);
//r.db("my_database").table("my_table").indexCreate("trap").run(connection);
}
if
(!
dbList
.
contains
(
dbAbout
))
{
System
.
out
.
println
(
"Creating DATABASE"
);
r
.
dbCreate
(
dbAbout
).
run
(
connection
);
}
List
<
String
>
aboutTables
=
r
.
db
(
dbAbout
).
tableList
().
run
(
connection
);
if
(!
tables
.
contains
(
dbTableAbout
))
{
System
.
out
.
println
(
"Creating Table"
);
if
(!
aboutTables
.
contains
(
dbTableAbout
))
{
System
.
out
.
println
(
"Creating About Table"
);
r
.
db
(
dbAbout
).
tableCreate
(
dbTableAbout
).
run
(
connection
);
}
}
catch
(
Exception
e
)
{
...
...
SNMP_Pipeline/Web-Application/src/main/java/com/example/WebApplication/services/RethinkDBService.java
View file @
c5b76f65
...
...
@@ -106,5 +106,56 @@ public class RethinkDBService{
return
null
;
}
}
public
long
getTrapCount
()
{
try
{
long
count
=
r
.
db
(
connectionFactory
.
getDbName
())
.
table
(
connectionFactory
.
getDbTableName
())
.
count
()
.
run
(
connectionFactory
.
getConnection
());
return
count
;
}
catch
(
Exception
e
)
{
log
.
error
(
"Error getting trap count from RethinkDB"
,
e
);
return
0
;
}
}
public
long
getErrorTrapCount
()
{
try
{
long
count
=
r
.
db
(
connectionFactory
.
getDbName
())
.
table
(
connectionFactory
.
getDbTableName
())
.
filter
(
r
.
hashMap
(
"severity"
,
"ERROR"
))
.
count
()
.
run
(
connectionFactory
.
getConnection
());
return
count
;
}
catch
(
Exception
e
)
{
log
.
error
(
"Error getting error trap count from RethinkDB"
,
e
);
return
0
;
}
}
public
long
getWarningTrapCount
()
{
try
{
long
count
=
r
.
db
(
connectionFactory
.
getDbName
())
.
table
(
connectionFactory
.
getDbTableName
())
.
filter
(
r
.
hashMap
(
"severity"
,
"WARNING"
))
.
count
()
.
run
(
connectionFactory
.
getConnection
());
return
count
;
}
catch
(
Exception
e
)
{
log
.
error
(
"Error getting warning trap count from RethinkDB"
,
e
);
return
0
;
}
}
public
long
getInfoTrapCount
()
{
try
{
long
count
=
r
.
db
(
connectionFactory
.
getDbName
())
.
table
(
connectionFactory
.
getDbTableName
())
.
filter
(
r
.
hashMap
(
"severity"
,
"INFO"
))
.
count
()
.
run
(
connectionFactory
.
getConnection
());
return
count
;
}
catch
(
Exception
e
)
{
log
.
error
(
"Error getting info trap count from RethinkDB"
,
e
);
return
0
;
}
}
}
SNMP_Pipeline/user-service/src/main/java/com/example/userService/controllers/UserController.java
View file @
c5b76f65
...
...
@@ -60,5 +60,23 @@ public class UserController {
return
false
;
}
}
@GetMapping
(
"/getAdminCount"
)
public
long
getAdminsCount
()
{
try
{
return
userService
.
getAdminsCount
();
}
catch
(
Exception
e
){
return
0
;
}
}
@GetMapping
(
"/getUsersCount"
)
public
long
getUsersCount
()
{
try
{
return
userService
.
getUsersCount
();
}
catch
(
Exception
e
){
return
0
;
}
}
}
SNMP_Pipeline/user-service/src/main/java/com/example/userService/repository/UserCredentialRepository.java
View file @
c5b76f65
package
com
.
example
.
userService
.
repository
;
import
com.example.userService.entity.UserCredential
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.stereotype.Repository
;
...
...
@@ -9,4 +10,9 @@ import java.util.Optional;
@Repository
public
interface
UserCredentialRepository
extends
CrudRepository
<
UserCredential
,
Integer
>
{
Optional
<
UserCredential
>
findByUsername
(
String
username
);
@Query
(
"SELECT COUNT(u) FROM UserCredential u WHERE u.role = 'admin'"
)
long
countAdmins
();
@Query
(
"SELECT COUNT(u) FROM UserCredential u WHERE u.role = 'user'"
)
long
countUsers
();
}
SNMP_Pipeline/user-service/src/main/java/com/example/userService/service/UserService.java
View file @
c5b76f65
...
...
@@ -69,4 +69,11 @@ public class UserService {
return
false
;
}
}
public
long
getAdminsCount
()
{
return
repository
.
countAdmins
();
}
public
long
getUsersCount
()
{
return
repository
.
countUsers
();
}
}
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