Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Commit

Permalink
API for CMDB integration
Browse files Browse the repository at this point in the history
  • Loading branch information
amreo committed Sep 11, 2020
1 parent 9464387 commit c8ff57d
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.ercole</groupId>
<artifactId>ercole-server</artifactId>
<version>1.6.14</version>
<version>1.6.17</version>

<properties>
<ercole-web.version>1.6.14</ercole-web.version>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/ercole/config/LdapSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ protected void configure(final HttpSecurity http) throws Exception {
.antMatchers("/packages/**").permitAll()
.antMatchers(pathUpdate).permitAll()
.antMatchers("/alerts/missing-host/**").permitAll()
.antMatchers("/alerts/missing-host-in-cmdb/**").permitAll()
.antMatchers("/hostnames-oracledb-for-agent").permitAll()
.anyRequest().fullyAuthenticated()
.and()
.formLogin()
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/io/ercole/controller/AgentDataController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.Base64;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -232,4 +233,22 @@ public void checkHostAbsence(final HttpServletRequest request, final @PathVariab
throw new AgentLoginException("Parametri user o password dell'agente errati.");
}
}

@PostMapping("/alerts/missing-host-in-cmdb/{hostname}")
public void checkHostAbsenceInCMDB(final HttpServletRequest request, final @PathVariable String hostname) throws AgentLoginException {
if (areAgentCredentialsValid(request.getHeader("Authorization"))) {
hostService.checkHostAbsenceInCMDB(hostname);
} else {
throw new AgentLoginException("Parametri user o password dell'agente errati.");
}
}

@GetMapping("/hostnames-oracledb-for-agent")
public List<String> getHostnames(final HttpServletRequest request) throws AgentLoginException {
if (areAgentCredentialsValid(request.getHeader("Authorization"))) {
return hostService.getHostnameOracleDB();
} else {
throw new AgentLoginException("Parametri user o password dell'agente errati.");
}
}
}
5 changes: 4 additions & 1 deletion src/main/java/io/ercole/model/AlertCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public enum AlertCode {
NO_DATA("No Data"),

/** The mssing host.*/
MISSING_HOST("Missing Host");
MISSING_HOST("Missing Host"),

/** The mssing host.*/
MISSING_HOST_IN_CMDB("Missing Host in CMDB");

/**
* Instantiates a new alert code.
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/io/ercole/model/AlertFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,22 @@ public Alert fireNewServerAlert(final String hostname) {
* @return an Alert for having added a new Server
*/
public Alert fireMissingHostAlert(final String hostname) {
String description = "Server " + hostname + " is missing";
String description = "Server " + hostname + " is missing from ercole";
return new Alert(hostname, AlertCode.MISSING_HOST, description,
AlertSeverity.NOTICE);
}


/**
* @param hostname is the Hostname
* @return an Alert for having added a new Server
*/
public Alert fireMissingHostInCMDBAlert(final String hostname) {
String description = "Server " + hostname + " is missing from CMDB";
return new Alert(hostname, AlertCode.MISSING_HOST_IN_CMDB, description,
AlertSeverity.NOTICE);
}

/**
* @param newDbs map of Databases incoming from agent
* @param oldActiveFeatures map of allready activated Features on server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public interface CurrentHostRepository extends PagingAndSortingRepository<Curren
*/
@Query("SELECT m FROM CurrentHost m")
Stream<CurrentHost> findAllHosts();

/**
* Gets hostname of hosts with oracledb.
*
* @return different types of active server locations
*/
@Query("SELECT m.hostname FROM CurrentHost m WHERE m.hostType IS NULL OR m.hostType = 'oracledb'")
List<String> getOracleDBHostnames();

/**
* Find by db.
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/io/ercole/services/GenerateExcelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,14 @@ public ResponseEntity<byte[]> initExcel() throws IOException {
dataOfHost[5] = host.getEnvironment();
dataOfHost[6] = JsonFilter.getTrueFeatures(features);
dataOfHost[7] = JsonFilter.getManagementPack(features);
if (String.valueOf(database.get(vrs)).contains(" ")) {
dataOfHost[12] = String.valueOf(database.get(vrs)).split(" ")[0]; //product version
dataOfHost[13] = String.valueOf(database.get(vrs)).substring(indexVersion);
} else {
dataOfHost[12] = String.valueOf(database.get(vrs)); //product version
dataOfHost[13] = String.valueOf(database.get(vrs));

dataOfHost[12] = String.valueOf(database.get(vrs)).substring(0, 2); //product version
dataOfHost[13] = String.valueOf(database.get(vrs)).substring(indexVersion);
}
if (String.valueOf(database.get(vrs)).toLowerCase().contains("standard")) {
dataOfHost[13] = "SE";
} else if (String.valueOf(database.get(vrs)).toLowerCase().contains("enterprise")) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/ercole/services/HostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,16 @@ public void checkHostAbsence(final String hostname) {
mailService.send(alert);
}
}

public void checkHostAbsenceInCMDB(final String hostname) {
if (!alertRepo.existsByHostnameAndCode(hostname, AlertCode.MISSING_HOST_IN_CMDB)) {
AlertFactory generator = new AlertFactory();
Alert alert = alertRepo.save(generator.fireMissingHostInCMDBAlert(hostname));
mailService.send(alert);
}
}

public List<String> getHostnameOracleDB() {
return currentRepo.getOracleDBHostnames();
}
}

0 comments on commit c8ff57d

Please sign in to comment.