Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(ui): check format of top counter's endpoints return data (#8187)
Browse files Browse the repository at this point in the history
Refs: MON-4590
  • Loading branch information
kduret committed Dec 12, 2019
1 parent 918e072 commit 4c87741
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 13 deletions.
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"redux-thunk": "^2.3.0",
"reselect": "^4.0.0",
"systemjs": "^6.1.3",
"systemjs-plugin-css": "^0.1.37"
"systemjs-plugin-css": "^0.1.37",
"yup": "^0.27.0"
},
"jest": {
"testResultsProcessor": "jest-junit",
Expand Down
4 changes: 2 additions & 2 deletions www/front_src/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class App extends Component {
axios('internal.php?object=centreon_keepalive&action=keepAlive')
.get()
.then(() => this.keepAlive())
.catch((error) => {
if (error.response.status === 401) {
.catch(error => {
if (error.response && error.response.status === 401) {
// redirect to login page
window.location.href = 'index.php?disconnect=1';
} else {
Expand Down
29 changes: 25 additions & 4 deletions www/front_src/src/components/hostMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

import React, { Component } from 'react';
import classnames from 'classnames';
import numeral from 'numeral';
import * as yup from 'yup';
import numeral from "numeral";
import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';
import { Translate } from 'react-redux-i18n';
Expand All @@ -19,6 +20,26 @@ import axios from '../../axios';

import styles from '../header/header.scss';

const numberFormat = yup
.number()
.required()
.integer();

const statusSchema = yup.object().shape({
down: yup.object().shape({
total: numberFormat,
unhandled: numberFormat,
}),
unreachable: yup.object().shape({
total: numberFormat,
unhandled: numberFormat,
}),
ok: numberFormat,
pending: numberFormat,
total: numberFormat,
refreshTime: numberFormat,
});

class HostMenu extends Component {
hostsService = axios(
'internal.php?object=centreon_topcounter&action=hosts_status',
Expand Down Expand Up @@ -46,12 +67,12 @@ class HostMenu extends Component {
this.hostsService
.get()
.then(({ data }) => {
this.setState({
data,
statusSchema.validate(data).then(() => {
this.setState({ data });
});
})
.catch((error) => {
if (error.response.status === 401) {
if (error.response && error.response.status === 401) {
this.setState({
data: null,
});
Expand Down
2 changes: 1 addition & 1 deletion www/front_src/src/components/pollerMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class PollerMenu extends Component {
});
})
.catch((error) => {
if (error.response.status === 401) {
if (error.response && error.response.status === 401) {
this.setState({
data: null,
});
Expand Down
31 changes: 28 additions & 3 deletions www/front_src/src/components/serviceStatusMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import React, { Component } from 'react';
import classnames from 'classnames';
import * as yup from 'yup';
import PropTypes from 'prop-types';
import numeral from 'numeral';
import { Link } from 'react-router-dom';
Expand All @@ -19,6 +20,30 @@ import axios from '../../axios';

import styles from '../header/header.scss';

const numberFormat = yup
.number()
.required()
.integer();

const statusSchema = yup.object().shape({
critical: yup.object().shape({
total: numberFormat,
unhandled: numberFormat,
}),
warning: yup.object().shape({
total: numberFormat,
unhandled: numberFormat,
}),
unknown: yup.object().shape({
total: numberFormat,
unhandled: numberFormat,
}),
ok: numberFormat,
pending: numberFormat,
total: numberFormat,
refreshTime: numberFormat,
});

class ServiceStatusMenu extends Component {
servicesStatusService = axios(
'internal.php?object=centreon_topcounter&action=servicesStatus',
Expand Down Expand Up @@ -46,12 +71,12 @@ class ServiceStatusMenu extends Component {
this.servicesStatusService
.get()
.then(({ data }) => {
this.setState({
data,
statusSchema.validate(data).then(() => {
this.setState({ data });
});
})
.catch((error) => {
if (error.response.status === 401) {
if (error.response && error.response.status === 401) {
this.setState({
data: null,
});
Expand Down
2 changes: 1 addition & 1 deletion www/front_src/src/components/userMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class UserMenu extends Component {
);
})
.catch((error) => {
if (error.response.status === 401) {
if (error.response && error.response.status === 401) {
this.setState({
data: null,
});
Expand Down
2 changes: 1 addition & 1 deletion www/front_src/src/translations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function setTranslations(store, callback) {
callback();
})
.catch((error) => {
if (error.response.status === 401) {
if (error.response && error.response.status === 401) {
// redirect to login page
window.location.href = 'index.php?disconnect=1';
}
Expand Down

0 comments on commit 4c87741

Please sign in to comment.