Commit e47acd41 authored by ReemyHasan's avatar ReemyHasan

add About page settings

parent 89927da6
<component name="libraryTable">
<library name="Maven: org.eclipse.angus:angus-activation:2.0.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/angus/angus-activation/2.0.1/angus-activation-2.0.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/angus/angus-activation/2.0.1/angus-activation-2.0.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/angus/angus-activation/2.0.1/angus-activation-2.0.1-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.eclipse.angus:jakarta.mail:1.1.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/angus/jakarta.mail/1.1.0/jakarta.mail-1.1.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/angus/jakarta.mail/1.1.0/jakarta.mail-1.1.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/angus/jakarta.mail/1.1.0/jakarta.mail-1.1.0-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.springframework.boot:spring-boot-starter-mail:3.1.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-mail/3.1.1/spring-boot-starter-mail-3.1.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-mail/3.1.1/spring-boot-starter-mail-3.1.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-mail/3.1.1/spring-boot-starter-mail-3.1.1-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.springframework:spring-context-support:6.0.10">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context-support/6.0.10/spring-context-support-6.0.10.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context-support/6.0.10/spring-context-support-6.0.10-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context-support/6.0.10/spring-context-support-6.0.10-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
......@@ -2,6 +2,6 @@ server.port = 0
spring.kafka.bootstrap-servers=http://172.29.3.220:9092
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.listener.address=192.168.26.46/1625
spring.listener.address=192.168.93.198/1625
spring.listener.threads=20
spring.listener.community=public
......@@ -2,6 +2,6 @@ server.port = 0
spring.kafka.bootstrap-servers=http://172.29.3.220:9092
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.listener.address=192.168.26.46/1625
spring.listener.address=192.168.93.198/1625
spring.listener.threads=20
spring.listener.community=public
......@@ -73,7 +73,10 @@
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
......
......@@ -15,7 +15,7 @@ import java.util.List;
import java.util.Map;
@RestController
@CrossOrigin("192.168.25.254:3000")
@CrossOrigin("*")
@RequestMapping("/api/rethink")
public class RethinkController {
@Autowired
......@@ -27,7 +27,7 @@ public class RethinkController {
@GetMapping("/data")
public ResponseEntity<List<Map<String, Object>>> getData() {
List<Map<String, Object>> result = rethinkDBService.getData();
System.out.println(result);
// System.out.println(result);
if (result != null) {
return ResponseEntity.ok(result);
} else {
......
package com.example.WebApplication.controller;
import com.example.WebApplication.entities.AboutInfo;
import com.example.WebApplication.services.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@CrossOrigin("*")
@RequestMapping("/api/about")
public class SettingController {
@Autowired
private SettingService settingService;
@DeleteMapping("/delete/{key}")
public void delete(@PathVariable String key){
settingService.deleteAboutInfo(key);
}
@GetMapping("/get/{key}")
public ResponseEntity<AboutInfo> getByKey(@PathVariable String key) {
AboutInfo result = settingService.getByKey(key);
System.out.println(result);
if (result != null) {
return ResponseEntity.ok(result);
} else {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
@GetMapping("/data")
public ResponseEntity<List<Map<String, AboutInfo>>> getData() {
List<Map<String, AboutInfo>> result = settingService.getData();
System.out.println(result);
if (result != null) {
return ResponseEntity.ok(result);
} else {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
@PostMapping("/post")
public ResponseEntity<Boolean> postData(@RequestBody AboutInfo aboutInfo) {
boolean result = settingService.putAboutInfo(aboutInfo);
if (result == true) {
return ResponseEntity.ok(result);
} else {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
@PutMapping("/update")
public ResponseEntity<Boolean> UpdateData(@RequestBody AboutInfo aboutInfo) {
try {
Boolean result = settingService.updateAboutInfo(aboutInfo);
return ResponseEntity.ok(result);
}catch(Exception e){
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
@PostMapping("/send-message")
public ResponseEntity<Boolean> sendMessage(@RequestBody Map<String, String> message ) {
try {
String subject = message.get("subject");
String body = message.get("body");
String email = message.get("email");
settingService.sendMessage(subject, body, email);
return ResponseEntity.ok(true);
}catch (Exception e){
return ResponseEntity.ok(false);
}
}
}
......@@ -55,7 +55,7 @@ public class SocketTextHandler extends TextWebSocketHandler implements CommandLi
System.out.println(message);
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(message);
System.out.println(json);
// System.out.println(json);
TextMessage s = new TextMessage(json);
//System.out.println(s);
for (WebSocketSession session : sessions) {
......@@ -72,7 +72,7 @@ public class SocketTextHandler extends TextWebSocketHandler implements CommandLi
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
System.out.println(json);
// System.out.println(json);
TextMessage s = new TextMessage(json);
if (session.isOpen()) {
try {
......
package com.example.WebApplication.entities;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class AboutInfo {
@JsonProperty("key")
public String key;
@JsonProperty("value")
public String value;
}
......@@ -33,6 +33,12 @@ public class RethinkDBConnectionFactory {
@Value("${rethinkDBTableName}")
private String dbTableName;
@Value("${rethinkDBAbout}")
private String dbAbout;
@Value("${rethinkDBAboutTable}")
private String dbTableAbout;
@PostConstruct
public Connection init() {
try {
......@@ -40,18 +46,28 @@ public class RethinkDBConnectionFactory {
log.info("RethinkDB connected successfully");
List<String> dbList = r.dbList().run(connection);
if (!dbList.contains(dbName)) {
// System.out.println("Creating DATABASE Heeeeeeeeeeeeeeeeeeeeeeeeeere");
System.out.println("Creating DATABASE");
r.dbCreate(dbName).run(connection);
}
List<String> tables = r.db(dbName).tableList().run(connection);
if (!tables.contains(dbTableName)) {
// System.out.println("Creating Table Heeeeeeeeeeeeeeeeeeeeeeeeeere");
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");
r.db(dbAbout).tableCreate(dbTableAbout).run(connection);
}
} catch (Exception e) {
log.error("Error connecting to RethinkDB", e);
log.error("Error connecting to RethinkDB");
}
return null;
}
......
package com.example.WebApplication.services;
import com.example.WebApplication.entities.AboutInfo;
import com.example.WebApplication.factory.RethinkDBConnectionFactory;
import com.rethinkdb.RethinkDB;
import com.rethinkdb.net.Cursor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class SettingService {
@Autowired
private JavaMailSender mailSender;
private final Logger log = LoggerFactory.getLogger(RethinkDBService.class);
private final RethinkDB r = RethinkDB.r;
@Autowired
public RethinkDBConnectionFactory connectionFactory;
public List<Map<String, AboutInfo>> getData() {
try {
Cursor<Map<String, AboutInfo>> cursor = r.db(connectionFactory.getDbAbout()).table(connectionFactory.getDbTableAbout()).run(connectionFactory.getConnection());
List<Map<String, AboutInfo>> result = new ArrayList<>();
while (cursor.hasNext()) {
result.add(cursor.next());
}
return result;
} catch (Exception e) {
log.error("Error getting data from RethinkDB", e);
return null;
}
}
public AboutInfo getByKey(String key) {
try {
Cursor<Map<String, AboutInfo>> cursor = r.db(connectionFactory.getDbAbout())
.table(connectionFactory.getDbTableAbout())
.filter(row -> row.g("key").eq(key))
.run(connectionFactory.getConnection());
if (cursor.hasNext()) {
return cursor.next().get("value");
} else {
return null;
}
} catch (Exception e) {
log.error("Error getting data from RethinkDB", e);
return null;
}
}
public boolean putAboutInfo(AboutInfo aboutInfo) {
try {
r.db(connectionFactory.getDbAbout())
.table(connectionFactory.getDbTableAbout())
.insert(r.hashMap("key", aboutInfo.getKey())
.with("value", aboutInfo.getValue()))
.run(connectionFactory.getConnection());
return true;
} catch (Exception e) {
log.error("Error saving data to RethinkDB", e);
return false;
}
}
public boolean updateAboutInfo(AboutInfo aboutInfo) {
try {
r.db(connectionFactory.getDbAbout())
.table(connectionFactory.getDbTableAbout())
.filter(row -> row.g("key").eq(aboutInfo.getKey()))
.update(r.hashMap("value", aboutInfo.getValue()))
.run(connectionFactory.getConnection());
return true;
} catch (Exception e) {
log.error("Error updating data in RethinkDB", e);
return false;
}
}
public void deleteAboutInfo(String key) {
try {
r.db(connectionFactory.getDbAbout())
.table(connectionFactory.getDbTableAbout())
.filter(row -> row.g("key").eq(key))
.delete()
.run(connectionFactory.getConnection());
} catch (Exception e) {
log.error("Error deleting data from RethinkDB", e);
}
}
public void sendMessage(String subject, String body, String email){
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("projectfms6@gmail.com");
message.setTo("projectfms6@gmail.com");
message.setText(email+"\n"+body);
message.setSubject("FeedBack from: "+subject);
mailSender.send(message);
System.out.println("Mail Send...");
}
}
......@@ -4,4 +4,12 @@ rethinkdb.port = 28015
rethinkDBName = Traps
rethinkDBTableName = Raw-Traps
websocket.path = /fms-websocket
rethinkDBAbout = About
rethinkDBAboutTable = About-table
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=projectfms6@gmail.com
spring.mail.password=qajvviuzidnrimnh
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
......@@ -7,6 +7,7 @@ import org.snmp4j.PDUv1;
import org.snmp4j.smi.VariableBinding;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Setter
@Getter
......@@ -22,6 +23,8 @@ public class EnrichedTrap {
@JsonProperty("timestamp")
public long timestamp;
@JsonProperty("date")
public long date;
@JsonProperty("severity")
public SeverityLevel severity;
......@@ -35,6 +38,7 @@ public class EnrichedTrap {
this.timestamp = pdu.getTimestamp();
this.agentAddress = pdu.getAgentAddress().toString();
this.variableBindings = pdu.getVariableBindings();
this.date = new Date().getTime();
if (this.variableBindings.size() > 5){
this.severity = SeverityLevel.WARNING;
}
......
......@@ -26,9 +26,8 @@ public class RethinkDBService {
public void saveKafkaMessageToRethink(EnrichedTrap rethinkTrap) {
try {
System.out.println(rethinkTrap.getDate());
ObjectMapper objectMapper = new ObjectMapper();
//
String jsonString = objectMapper.writeValueAsString(rethinkTrap);
JsonNode jsonNode = objectMapper.readTree(jsonString);
Map<String,EnrichedTrap> document = objectMapper.convertValue(jsonNode, Map.class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment