Skip to content

Commit

Permalink
[backend/frontend] get rabbitmq version and fix value in frontend (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumejparis authored May 27, 2024
1 parent f683c1a commit fb55f98
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 8 deletions.
57 changes: 57 additions & 0 deletions openbas-api/src/main/java/io/openbas/helper/RabbitMQHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.openbas.helper;

import io.openbas.config.AppSecurityConfig;
import io.openbas.config.OpenBASConfig;
import io.openbas.config.RabbitmqConfig;
import org.springframework.boot.json.BasicJsonParser;
import org.springframework.http.*;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;
import java.util.logging.Level;
import java.util.logging.Logger;

public class RabbitMQHelper {

private static final Logger LOGGER = Logger.getLogger(RabbitMQHelper.class.getName());

private static String rabbitMQVersion;

/**
* Return the version of Rabbit MQ we're using
*
* @return the rabbit MQ version
*/
public static String getRabbitMQVersion(RabbitmqConfig rabbitmqConfig) {
// If we already have the version, we don't need to get it again
if (rabbitMQVersion == null) {
RestTemplate restTemplate = new RestTemplate();
// Init the rabbit MQ management api overview url
String uri = rabbitmqConfig.isSsl() ? "https://" : "http://"
+ rabbitmqConfig.getHostname() + ":" + rabbitmqConfig.getManagementPort()
+ "/api/overview";

// Init the headers
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setBasicAuth(rabbitmqConfig.getUser(), rabbitmqConfig.getPass());
HttpEntity<String> entity = new HttpEntity<>("parameters", headers);

// Make the call
ResponseEntity<?> result = null;
try {
result = restTemplate.exchange(uri, HttpMethod.GET, entity, String.class);
} catch (RestClientException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
return null;
}

// Init the parser to get the rabbit_mq version
BasicJsonParser jsonParser = new BasicJsonParser();
rabbitMQVersion = (String) jsonParser.parseMap((String) result.getBody()).get("rabbitmq_version");
}

return rabbitMQVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import io.openbas.config.OpenBASConfig;
import io.openbas.config.OpenBASPrincipal;
import io.openbas.config.RabbitmqConfig;
import io.openbas.database.model.Setting;
import io.openbas.database.model.Theme;
import io.openbas.database.repository.SettingRepository;
import io.openbas.executors.caldera.config.CalderaExecutorConfig;
import io.openbas.helper.RabbitMQHelper;
import io.openbas.injectors.opencti.config.OpenCTIConfig;
import io.openbas.rest.helper.RestBehavior;
import io.openbas.rest.settings.form.SettingsEnterpriseEditionUpdateInput;
Expand Down Expand Up @@ -59,6 +61,8 @@ public class PlatformSettingsApi extends RestBehavior {

@Resource
private OpenBASConfig openBASConfig;
@Resource
private RabbitmqConfig rabbitmqConfig;

@Autowired
public void setOpenCTIConfig(OpenCTIConfig openCTIConfig) {
Expand Down Expand Up @@ -205,6 +209,7 @@ public PlatformSettings settings() {
platformSettings.setPlatformVersion(openBASConfig.getVersion());
platformSettings.setPostgreVersion(settingRepository.getServerVersion());
platformSettings.setJavaVersion(Runtime.version().toString());
platformSettings.setRabbitMQVersion(RabbitMQHelper.getRabbitMQVersion(rabbitmqConfig));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import io.openbas.rest.settings.form.ThemeInput;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

Expand Down Expand Up @@ -63,6 +66,9 @@ public class PlatformSettings {
@JsonProperty("java_version")
private String javaVersion;

@JsonProperty("rabbitmq_version")
private String rabbitMQVersion;

@JsonProperty("platform_ai_enabled")
private Boolean aiEnabled;

Expand Down
1 change: 1 addition & 0 deletions openbas-api/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ openbas.rabbitmq.hostname=localhost
openbas.rabbitmq.vhost=/
openbas.rabbitmq.ssl=false
openbas.rabbitmq.port=5672
openbas.rabbitmq.management-port=15672
openbas.rabbitmq.user=guest
openbas.rabbitmq.pass=guest
openbas.rabbitmq.queue-type=classic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class RabbitmqConfig {
@JsonProperty("rabbitmq_port")
private int port;

@JsonProperty("rabbitmq_management-port")
private int managementPort;

@JsonProperty("rabbitmq_user")
private String user;

Expand Down
2 changes: 1 addition & 1 deletion openbas-front/src/admin/components/settings/Parameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const Parameters = () => {
</ListItem>
<ListItem divider={true}>
<ListItemText primary={t('RabbitMQ')} />
<ItemBoolean status={null} variant="large" neutralLabel={settings?.postgre_version} />
<ItemBoolean status={null} variant="large" neutralLabel={settings?.rabbitmq_version} />
</ListItem>
</List>
</Paper>
Expand Down
80 changes: 74 additions & 6 deletions openbas-front/src/utils/api-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface Asset {
asset_last_seen?: string;
asset_name: string;
asset_parent?: Asset;
asset_process_name?: string;
asset_tags?: Tag[];
asset_type?: string;
/** @format date-time */
Expand Down Expand Up @@ -494,7 +495,7 @@ export interface DryInject {

export interface DryInjectStatus {
status_id?: string;
status_name?: "DRAFT" | "INFO" | "QUEUING" | "PENDING" | "PARTIAL" | "ERROR" | "SUCCESS";
status_name?: "DRAFT" | "INFO" | "QUEUING" | "EXECUTING" | "PENDING" | "PARTIAL" | "ERROR" | "SUCCESS";
status_traces?: InjectStatusExecution[];
/** @format date-time */
tracking_ack_date?: string;
Expand Down Expand Up @@ -553,14 +554,15 @@ export interface Endpoint {
asset_last_seen?: string;
asset_name: string;
asset_parent?: Asset;
asset_process_name?: string;
asset_tags?: Tag[];
asset_type?: string;
/** @format date-time */
asset_updated_at?: string;
endpoint_hostname?: string;
endpoint_ips: string[];
endpoint_mac_addresses?: string[];
endpoint_platform: "Linux" | "Windows" | "MacOS" | "Service" | "Generic" | "Internal";
endpoint_platform: "Linux" | "Windows" | "MacOS" | "Service" | "Generic" | "Internal" | "Unknown";
updateAttributes?: object;
}

Expand All @@ -577,7 +579,7 @@ export interface EndpointInput {
*/
endpoint_ips: string[];
endpoint_mac_addresses?: string[];
endpoint_platform: "Linux" | "Windows" | "MacOS" | "Service" | "Generic" | "Internal";
endpoint_platform: "Linux" | "Windows" | "MacOS" | "Service" | "Generic" | "Internal" | "Unknown";
}

export interface Evaluation {
Expand Down Expand Up @@ -931,6 +933,7 @@ export interface InjectExpectation {
inject_expectation_results?: InjectExpectationResult[];
/** @format int32 */
inject_expectation_score?: number;
inject_expectation_signatures?: InjectExpectationSignature[];
inject_expectation_status?: "FAILED" | "PENDING" | "PARTIAL" | "UNKNOWN" | "VALIDATED";
inject_expectation_team?: Team;
inject_expectation_type: "TEXT" | "DOCUMENT" | "ARTICLE" | "CHALLENGE" | "MANUAL" | "PREVENTION" | "DETECTION";
Expand All @@ -957,6 +960,11 @@ export interface InjectExpectationResultsByType {
results?: ExpectationResultsByType[];
}

export interface InjectExpectationSignature {
type?: string;
value?: string;
}

export interface InjectInput {
inject_all_teams?: boolean;
inject_asset_groups?: string[];
Expand Down Expand Up @@ -1011,7 +1019,7 @@ export interface InjectResultDTO {

export interface InjectStatus {
status_id?: string;
status_name?: "DRAFT" | "INFO" | "QUEUING" | "PENDING" | "PARTIAL" | "ERROR" | "SUCCESS";
status_name?: "DRAFT" | "INFO" | "QUEUING" | "EXECUTING" | "PENDING" | "PARTIAL" | "ERROR" | "SUCCESS";
status_traces?: InjectStatusExecution[];
/** @format date-time */
tracking_ack_date?: string;
Expand All @@ -1036,7 +1044,7 @@ export interface InjectStatusExecution {
/** @format int32 */
execution_duration?: number;
execution_message?: string;
execution_status?: "DRAFT" | "INFO" | "QUEUING" | "PENDING" | "PARTIAL" | "ERROR" | "SUCCESS";
execution_status?: "DRAFT" | "INFO" | "QUEUING" | "EXECUTING" | "PENDING" | "PARTIAL" | "ERROR" | "SUCCESS";
/** @format date-time */
execution_time?: string;
}
Expand All @@ -1050,7 +1058,7 @@ export interface InjectTargetWithResult {
expectationResultsByTypes?: ExpectationResultsByType[];
id: string;
name?: string;
platformType?: "Linux" | "Windows" | "MacOS" | "Service" | "Generic" | "Internal";
platformType?: "Linux" | "Windows" | "MacOS" | "Service" | "Generic" | "Internal" | "Unknown";
targetType?: "ASSETS" | "ASSETS_GROUPS" | "TEAMS";
}

Expand Down Expand Up @@ -1592,6 +1600,25 @@ export interface PageEndpoint {
totalPages?: number;
}

export interface PageExerciseSimple {
content?: ExerciseSimple[];
empty?: boolean;
first?: boolean;
last?: boolean;
/** @format int32 */
number?: number;
/** @format int32 */
numberOfElements?: number;
pageable?: PageableObject;
/** @format int32 */
size?: number;
sort?: SortObject[];
/** @format int64 */
totalElements?: number;
/** @format int32 */
totalPages?: number;
}

export interface PageFullTextSearchResult {
content?: FullTextSearchResult[];
empty?: boolean;
Expand Down Expand Up @@ -1878,6 +1905,7 @@ export interface PlatformSettings {
platform_version?: string;
platform_whitemark?: string;
postgre_version?: string;
rabbitmq_version?: string;
xtm_opencti_enable?: boolean;
xtm_opencti_url?: string;
}
Expand Down Expand Up @@ -1929,6 +1957,46 @@ export interface PublicExercise {
exercise_name?: string;
}

export interface RawAttackPattern {
attack_pattern_created_at?: string;
attack_pattern_description?: string;
attack_pattern_external_id?: string;
attack_pattern_id?: string;
attack_pattern_kill_chain_phases?: string[];
attack_pattern_name?: string;
attack_pattern_parent?: string;
attack_pattern_permissions_required?: string[];
attack_pattern_platforms?: string[];
attack_pattern_stix_id?: string;
attack_pattern_updated_at?: string;
}

export interface RawDocument {
document_description?: string;
document_exercises?: string[];
document_id?: string;
document_name?: string;
document_scenarios?: string[];
document_tags?: string[];
document_target?: string;
document_type?: string;
}

export interface RawUser {
/** @format date-time */
user_created_at?: string;
user_email?: string;
user_firstname?: string;
user_gravatar?: string;
user_groups?: string[];
user_id?: string;
user_lastname?: string;
user_organization?: string;
user_phone?: string;
user_tags?: string[];
user_teams?: string[];
}

export interface RenewTokenInput {
token_id: string;
}
Expand Down

0 comments on commit fb55f98

Please sign in to comment.