mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix conflicts
This commit is contained in:
@@ -20,8 +20,13 @@ child_process.execSync('react-env', {
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'build')));
|
||||
|
||||
app.get('/env.js', function (req, res) {
|
||||
res.sendFile(path.join(__dirname, 'public', 'env.js'));
|
||||
});
|
||||
|
||||
app.get('/*', function (req, res) {
|
||||
res.sendFile(path.join(__dirname, 'build', 'index.html'));
|
||||
});
|
||||
|
||||
|
||||
app.listen(3003);
|
||||
@@ -26,7 +26,7 @@ if (!isServer) {
|
||||
} else if (env('BACKEND_HOST')) {
|
||||
apiUrl = env('BACKEND_HOST');
|
||||
dashboardUrl = env('DASHBOARD_HOST');
|
||||
domain = 'host';
|
||||
domain = '.fyipe.com';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ var NotificationService = require('../services/notificationService');
|
||||
var RealTimeService = require('../services/realTimeService');
|
||||
var ScheduleService = require('../services/scheduleService');
|
||||
|
||||
|
||||
var router = express.Router();
|
||||
var isUserAdmin = require('../middlewares/project').isUserAdmin;
|
||||
var getUser = require('../middlewares/user').getUser;
|
||||
@@ -41,7 +40,7 @@ router.post('/:projectId', getUser, isAuthorized, isUserAdmin, async function (r
|
||||
}
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
|
||||
if(data.monitorCategoryId && typeof data.monitorCategoryId !== 'string') {
|
||||
if (data.monitorCategoryId && typeof data.monitorCategoryId !== 'string') {
|
||||
return sendErrorResponse(req, res, {
|
||||
code: 400,
|
||||
message: 'Monitor Category ID is not of string type.'
|
||||
@@ -138,7 +137,7 @@ router.post('/:projectId', getUser, isAuthorized, isUserAdmin, async function (r
|
||||
data.projectId = projectId;
|
||||
try {
|
||||
var monitor = await MonitorService.create(data);
|
||||
if (data.callScheduleId){
|
||||
if (data.callScheduleId) {
|
||||
var schedule = await ScheduleService.findOneBy({ _id: data.callScheduleId });
|
||||
var monitors = schedule.monitorIds;
|
||||
if (monitors.length > 0) {
|
||||
@@ -193,19 +192,27 @@ router.get('/:projectId', getUser, isAuthorized, getSubProjects, async function
|
||||
|
||||
router.get('/:projectId/monitor', getUser, isAuthorized, async function (req, res) {
|
||||
var projectId = req.params.projectId;
|
||||
try{
|
||||
var monitors = await MonitorService.findBy({projectId}, req.query.limit || 10, req.query.skip || 0);
|
||||
var count = await MonitorService.countBy({projectId});
|
||||
var type = req.query.type;
|
||||
var query = type ? { projectId, type } : { projectId };
|
||||
|
||||
try {
|
||||
var monitors = await MonitorService.findBy(query, req.query.limit || 10, req.query.skip || 0);
|
||||
var count = await MonitorService.countBy({ projectId });
|
||||
return sendListResponse(req, res, monitors, count); // frontend expects sendListResponse
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/:projectId/monitor/:monitorId', getUser, isAuthorized, async function (req, res) {
|
||||
var _id = req.params.monitorId;
|
||||
var projectId = req.params.projectId;
|
||||
var type = req.query.type;
|
||||
var query = type ? { _id, projectId, type } : { _id, projectId };
|
||||
|
||||
try {
|
||||
// Call the MonitorService.
|
||||
var monitor = await MonitorService.findOneBy({ _id: req.params.monitorId, projectId: req.params.projectId });
|
||||
var monitor = await MonitorService.findOneBy(query);
|
||||
return sendItemResponse(req, res, monitor);
|
||||
} catch (error) {
|
||||
return sendErrorResponse(req, res, error);
|
||||
@@ -227,6 +234,24 @@ router.delete('/:projectId/:monitorId', getUser, isAuthorized, isUserAdmin, asyn
|
||||
}
|
||||
});
|
||||
|
||||
// Route
|
||||
// Description: Adding / Updating a new monitor log
|
||||
// Params:
|
||||
// Param 1: req.params-> {projectId, monitorId}; req.body -> {[_id], data} <- Check MonitorLogModel for description.
|
||||
// Returns: response status, error message
|
||||
router.post('/:projectId/log/:monitorId', getUser, isAuthorized, isUserAdmin, async function (req, res) {
|
||||
var data = req.body.data;
|
||||
// var projectId = req.params.projectId;
|
||||
var monitorId = req.params.monitorId || req.body._id;
|
||||
|
||||
try {
|
||||
var monitorData = await MonitorService.addMonitorLog(monitorId, data);
|
||||
return sendItemResponse(req, res, monitorData);
|
||||
} catch (error) {
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/:projectId/inbound/:deviceId', getUser, isAuthorized, async function (req, res) {
|
||||
return await _updateDeviceMonitorPingTime(req, res);
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ var monitorSchema = new Schema({
|
||||
createdById: { type: String, ref: 'User' }, //userId.
|
||||
type: {
|
||||
type: String,
|
||||
enum: ['url', 'device', 'manual','api', 'script']
|
||||
enum: ['url', 'device', 'manual','api', 'server-monitor', 'script']
|
||||
}, //type can be 'url', 'process', 'machine'. We can monitor URL, a process in a machine or a server itself.
|
||||
monitorCategoryId: {
|
||||
type: String,
|
||||
|
||||
@@ -7,6 +7,7 @@ var monitorLogSchema = new Schema({
|
||||
responseTime: Number, // Time taken for ping
|
||||
responseStatus: Number,
|
||||
status: String,
|
||||
data: Object,
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
|
||||
@@ -8,22 +8,22 @@ module.exports = {
|
||||
var subProject = null;
|
||||
try {
|
||||
var project = await ProjectService.findOneBy({ _id: data.projectId });
|
||||
}catch (error) {
|
||||
} catch (error) {
|
||||
ErrorService.log('ProjectService.findOneBy', error);
|
||||
throw error;
|
||||
}
|
||||
if(project.parentProjectId){
|
||||
if (project.parentProjectId) {
|
||||
subProject = project;
|
||||
try {
|
||||
project = await ProjectService.findOneBy({ _id: subProject.parentProjectId });
|
||||
}catch (error) {
|
||||
} catch (error) {
|
||||
ErrorService.log('ProjectService.findOneBy', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
var subProjectIds = [];
|
||||
var subProjects = await ProjectService.findBy({ parentProjectId: project._id });
|
||||
if(subProjects && subProjects.length > 0){
|
||||
if (subProjects && subProjects.length > 0) {
|
||||
subProjectIds = subProjects.map(project => project._id);
|
||||
}
|
||||
subProjectIds.push(project._id);
|
||||
@@ -80,11 +80,11 @@ module.exports = {
|
||||
monitor.criteria = data.criteria || {};
|
||||
}
|
||||
if (data.type === 'api') {
|
||||
if(data.method && data.method.length) monitor.method = data.method;
|
||||
if(data.bodyType && data.bodyType.length) monitor.bodyType = data.bodyType;
|
||||
if(data.text && data.text.length) monitor.text = data.text;
|
||||
if(data.formData && data.formData.length) monitor.formData = data.formData;
|
||||
if(data.headers && data.headers.length) monitor.headers = data.headers;
|
||||
if (data.method && data.method.length) monitor.method = data.method;
|
||||
if (data.bodyType && data.bodyType.length) monitor.bodyType = data.bodyType;
|
||||
if (data.text && data.text.length) monitor.text = data.text;
|
||||
if (data.formData && data.formData.length) monitor.formData = data.formData;
|
||||
if (data.headers && data.headers.length) monitor.headers = data.headers;
|
||||
}
|
||||
try {
|
||||
var savedMonitor = await monitor.save();
|
||||
@@ -118,7 +118,7 @@ module.exports = {
|
||||
new: true
|
||||
})
|
||||
.populate('projectId', 'name');
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('MonitorModel.findOneAndUpdate', error);
|
||||
throw error;
|
||||
}
|
||||
@@ -161,7 +161,7 @@ module.exports = {
|
||||
.limit(limit)
|
||||
.skip(skip)
|
||||
.populate('projectId', 'name');
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('MonitorModel.find', error);
|
||||
throw error;
|
||||
}
|
||||
@@ -177,7 +177,7 @@ module.exports = {
|
||||
try {
|
||||
var monitor = await MonitorModel.findOne(query)
|
||||
.populate('projectId', 'name');
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('MonitorModel.findOne', error);
|
||||
throw error;
|
||||
}
|
||||
@@ -214,32 +214,32 @@ module.exports = {
|
||||
ErrorService.log('MonitorModel.findOneAndUpdate', error);
|
||||
throw error;
|
||||
}
|
||||
if(monitor){
|
||||
if (monitor) {
|
||||
var subProject = null;
|
||||
try {
|
||||
var project = await ProjectService.findOneBy({ _id: monitor.projectId });
|
||||
}catch (error) {
|
||||
} catch (error) {
|
||||
ErrorService.log('ProjectService.findOneBy', error);
|
||||
throw error;
|
||||
}
|
||||
if(project.parentProjectId){
|
||||
if (project.parentProjectId) {
|
||||
subProject = project;
|
||||
try {
|
||||
project = await ProjectService.findOneBy({ _id: subProject.parentProjectId });
|
||||
}catch (error) {
|
||||
} catch (error) {
|
||||
ErrorService.log('ProjectService.findOneBy', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
var subProjectIds = [];
|
||||
var subProjects = await ProjectService.findBy({ parentProjectId: project._id });
|
||||
if(subProjects && subProjects.length > 0){
|
||||
if (subProjects && subProjects.length > 0) {
|
||||
subProjectIds = subProjects.map(project => project._id);
|
||||
}
|
||||
subProjectIds.push(project._id);
|
||||
try{
|
||||
try {
|
||||
var monitorsCount = await this.countBy({ projectId: { $in: subProjectIds } });
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('MonitorService.countBy', error);
|
||||
throw error;
|
||||
}
|
||||
@@ -247,90 +247,90 @@ module.exports = {
|
||||
if (typeof (projectSeats) === 'string') {
|
||||
projectSeats = parseInt(projectSeats);
|
||||
}
|
||||
var projectUsers = await TeamService.getTeamMembersBy({parentProjectId: project._id}); // eslint-disable-next-line no-console
|
||||
var projectUsers = await TeamService.getTeamMembersBy({ parentProjectId: project._id }); // eslint-disable-next-line no-console
|
||||
var seats = await TeamService.getSeats(projectUsers);
|
||||
// check if project seats are more based on users in project or by count of monitors
|
||||
if (projectSeats && projectSeats > seats && monitorsCount > 0 && monitorsCount <= ((projectSeats - 1) * 5)) {
|
||||
projectSeats = projectSeats - 1;
|
||||
try{
|
||||
try {
|
||||
await PaymentService.changeSeats(project.stripeExtraUserSubscriptionId, (projectSeats));
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('PaymentService.changeSeats', error);
|
||||
throw error;
|
||||
}
|
||||
try{
|
||||
try {
|
||||
await ProjectService.update({ _id: project._id, seats: projectSeats.toString() });
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('ProjectService.update', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
try{
|
||||
try {
|
||||
var incidents = await IncidentService.findBy({ monitorId: monitor._id });
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('IncidentService.findBy', error);
|
||||
throw error;
|
||||
}
|
||||
await Promise.all(incidents.map(async(incident)=>{
|
||||
await IncidentService.deleteBy({_id: incident._id}, userId);
|
||||
await Promise.all(incidents.map(async (incident) => {
|
||||
await IncidentService.deleteBy({ _id: incident._id }, userId);
|
||||
}));
|
||||
try{
|
||||
try {
|
||||
var alerts = await AlertService.findBy({ monitorId: monitor._id }, userId);
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('AlertService.findBy', error);
|
||||
throw error;
|
||||
}
|
||||
await Promise.all(alerts.map(async(alert)=>{
|
||||
await AlertService.deleteBy({_id: alert._id}, userId);
|
||||
await Promise.all(alerts.map(async (alert) => {
|
||||
await AlertService.deleteBy({ _id: alert._id }, userId);
|
||||
}));
|
||||
try{
|
||||
try {
|
||||
await StatusPageService.removeMonitor(monitor._id);
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('StatusPageService.removeMonitor', error);
|
||||
throw error;
|
||||
}
|
||||
try{
|
||||
try {
|
||||
await ScheduleService.removeMonitor(monitor._id);
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('ScheduleService.deleteBy', error);
|
||||
throw error;
|
||||
}
|
||||
try{
|
||||
try {
|
||||
await IntegrationService.removeMonitor(monitor._id);
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('IntegrationService.removeMonitor', error);
|
||||
throw error;
|
||||
}
|
||||
try{
|
||||
try {
|
||||
await NotificationService.create(monitor.projectId, `A Monitor ${monitor.name} was deleted from the project by ${monitor.deletedById.name}`, monitor.deletedById._id, 'monitoraddremove');
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('NotificationService.create', error);
|
||||
throw error;
|
||||
}
|
||||
try{
|
||||
try {
|
||||
await RealTimeService.sendMonitorDelete(monitor);
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
ErrorService.log('RealTimeService.sendMonitorDelete', error);
|
||||
throw error;
|
||||
}
|
||||
return monitor;
|
||||
}else{
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
async getMonitors(subProjectIds, skip, limit){
|
||||
if(typeof skip === 'string') skip = parseInt(skip);
|
||||
if(typeof limit === 'string') limit = parseInt(limit);
|
||||
async getMonitors(subProjectIds, skip, limit) {
|
||||
if (typeof skip === 'string') skip = parseInt(skip);
|
||||
if (typeof limit === 'string') limit = parseInt(limit);
|
||||
var _this = this;
|
||||
let subProjectMonitors = await Promise.all(subProjectIds.map(async (id)=>{
|
||||
let subProjectMonitors = await Promise.all(subProjectIds.map(async (id) => {
|
||||
let monitors = await IncidentService.getMonitorsWithIncidentsBy({
|
||||
query: {projectId: id},
|
||||
query: { projectId: id },
|
||||
skip,
|
||||
limit
|
||||
});
|
||||
let count = await _this.countBy({projectId: id});
|
||||
return {monitors, count, _id: id, skip, limit};
|
||||
let count = await _this.countBy({ projectId: id });
|
||||
return { monitors, count, _id: id, skip, limit };
|
||||
}));
|
||||
return subProjectMonitors;
|
||||
},
|
||||
@@ -506,6 +506,23 @@ module.exports = {
|
||||
return monitorsData;
|
||||
},
|
||||
|
||||
// Description: Add Server Monitor Log Data
|
||||
async addMonitorLog(monitorId, data) {
|
||||
// var _this = this;
|
||||
var monitorLogData = new MonitorLogModel();
|
||||
monitorLogData.monitorId = monitorId;
|
||||
monitorLogData.status = 'online';
|
||||
monitorLogData.data = data;
|
||||
try {
|
||||
var monitorData = await monitorLogData.save();
|
||||
} catch (error) {
|
||||
ErrorService.log('monitorLogData.save', error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
return monitorData;
|
||||
},
|
||||
|
||||
async sendResponseTime(monitorsData) {
|
||||
try {
|
||||
var monitor = await MonitorModel.findOne({ _id: monitorsData.monitorId, deleted: false });
|
||||
@@ -513,7 +530,7 @@ module.exports = {
|
||||
ErrorService.log('MonitorModel.findOne', error);
|
||||
throw error;
|
||||
}
|
||||
if(monitor){
|
||||
if (monitor) {
|
||||
try {
|
||||
await RealTimeService.updateResponseTime(monitorsData, monitor.projectId);
|
||||
} catch (error) {
|
||||
@@ -702,6 +719,7 @@ module.exports = {
|
||||
|
||||
var MonitorModel = require('../models/monitor');
|
||||
var MonitorTimeModel = require('../models/monitorTime');
|
||||
var MonitorLogModel = require('../models/monitorLog');
|
||||
var MonitorCategoryService = require('../services/monitorCategoryService');
|
||||
var Plans = require('./../config/plans');
|
||||
var RealTimeService = require('./realTimeService');
|
||||
|
||||
@@ -20,6 +20,10 @@ child_process.execSync('react-env', {
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'build')));
|
||||
|
||||
app.get('/env.js', function (req, res) {
|
||||
res.sendFile(path.join(__dirname, 'public', 'env.js'));
|
||||
});
|
||||
|
||||
app.get('/*', function (req, res) {
|
||||
res.sendFile(path.join(__dirname, 'build', 'index.html'));
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@ import NotificationMenu from './notification/NotificationMenu';
|
||||
import { closeNotificationMenu } from '../actions/notification';
|
||||
|
||||
export class DashboardApp extends Component {
|
||||
// eslint-disable-next-line
|
||||
constructor(props){
|
||||
super(props);
|
||||
}
|
||||
@@ -103,7 +104,7 @@ export class DashboardApp extends Component {
|
||||
<div className="db-World-scrollWrapper" >
|
||||
|
||||
|
||||
<ShouldRender if={project.projects.projects != undefined && project.projects.projects[0]}>
|
||||
<ShouldRender if={project.projects.projects !== undefined && project.projects.projects[0]}>
|
||||
|
||||
<SideNav />
|
||||
|
||||
@@ -124,7 +125,7 @@ export class DashboardApp extends Component {
|
||||
<ShouldRender if={!project.projects.requesting && project.projects.success && location.pathname !== '/profile/settings'}>
|
||||
<div className="db-World-scrollWrapper" >
|
||||
|
||||
<ShouldRender if={ project.projects.projects != undefined && project.projects.projects[0]}>
|
||||
<ShouldRender if={ project.projects.projects !== undefined && project.projects.projects[0]}>
|
||||
|
||||
<SideNav />
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@ export function RenderIfUserInSubProject(props) {
|
||||
var renderItems = null;
|
||||
if (
|
||||
currentProject &&
|
||||
currentProject.users.filter(user => user.userId === userId && user.role != 'Viewer').length > 0)
|
||||
currentProject.users.filter(user => user.userId === userId && user.role !== 'Viewer').length > 0)
|
||||
{
|
||||
renderItems = children
|
||||
}else{
|
||||
if(subProjects){
|
||||
subProjects.forEach((subProject)=>{
|
||||
if (subProject._id === subProjectId && subProject.users.filter(user => user.userId === userId && user.role != 'Viewer').length > 0){
|
||||
if (subProject._id === subProjectId && subProject.users.filter(user => user.userId === userId && user.role !== 'Viewer').length > 0){
|
||||
renderItems = children
|
||||
}
|
||||
});
|
||||
|
||||
@@ -172,7 +172,7 @@ export class RenderOption extends Component {
|
||||
onClick={() => addField()}
|
||||
style={{ borderRadius: '50%', padding: '0px 6px' }}
|
||||
>
|
||||
<img src='/assets/img/plus.svg' style={{ height: '10px', width: '10px' }} />
|
||||
<img src='/assets/img/plus.svg' style={{ height: '10px', width: '10px' }} alt="" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -187,7 +187,7 @@ export class RenderOption extends Component {
|
||||
onClick={() => removeField(removeArrayField)}
|
||||
style={{ borderRadius: '50%', padding: '0px 6px' }}
|
||||
>
|
||||
<img src='/assets/img/minus.svg' style={{ height: '10px', width: '10px' }} />
|
||||
<img src='/assets/img/minus.svg' style={{ height: '10px', width: '10px' }} alt="" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -202,7 +202,7 @@ export class RenderOption extends Component {
|
||||
onClick={() => addArrayField(fieldnameprop)}
|
||||
style={{ borderRadius: '50%', padding: '0px 6px' }}
|
||||
>
|
||||
<img src='/assets/img/more.svg' style={{ height: '10px', width: '10px' }} />
|
||||
<img src='/assets/img/more.svg' style={{ height: '10px', width: '10px' }} alt="" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -14,10 +14,10 @@ const TeamSelector = ({ input, meta: { touched, error }, members }) => (
|
||||
<option value="">{input.defaultValue || 'Select Team Member...'}</option>
|
||||
{
|
||||
members.map(member => {
|
||||
return member.role != 'Viewer' ? (
|
||||
<option value={member.userId} key={member.name}>
|
||||
{member.name}
|
||||
</option>
|
||||
return member.role !== 'Viewer' ? (
|
||||
<option value={member.userId} key={member.name}>
|
||||
{member.name}
|
||||
</option>
|
||||
) : false;
|
||||
})
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ function validate(values) {
|
||||
}
|
||||
|
||||
export class AddMonitorCategoryForm extends React.Component {
|
||||
// eslint-disable-next-line
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@@ -306,6 +306,7 @@ class NewMonitor extends Component {
|
||||
<option value="manual">Manual</option>
|
||||
<option value="api">API</option>
|
||||
<option value="script">Script</option>
|
||||
<option value="serverMonitor">Server Monitor</option>
|
||||
</Field>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,6 +10,7 @@ import RenderOptions from '../basic/RenderOptions';
|
||||
import {RenderSelect} from '../basic/RenderSelect';
|
||||
|
||||
export class ResponseParent extends Component {
|
||||
// eslint-disable-next-line
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@@ -94,11 +94,11 @@ const mapStateToProps = (state, props) => {
|
||||
|
||||
const { projects } = state.project.projects;
|
||||
|
||||
const project = projects != undefined && projects.length > 0 ? projects.filter(
|
||||
const project = projects !== undefined && projects.length > 0 ? projects.filter(
|
||||
project => project._id === projectId
|
||||
)[0] : [];
|
||||
|
||||
const nextProject = projects != undefined && projects.length > 0 ? projects.filter(
|
||||
const nextProject = projects !== undefined && projects.length > 0 ? projects.filter(
|
||||
project => project._id !== projectId
|
||||
)[0] : {};
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ function validate(values) {
|
||||
}
|
||||
|
||||
export class ScheduleForm extends React.Component{
|
||||
// eslint-disable-next-line
|
||||
constructor(props){
|
||||
super(props);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ function validate(values) {
|
||||
}
|
||||
|
||||
export class StatusPageForm extends React.Component{
|
||||
// eslint-disable-next-line
|
||||
constructor(props){
|
||||
super(props);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ export class SubscriberList extends Component {
|
||||
<a className="db-ListViewItem-link" >
|
||||
<div className="db-ListViewItem-cellContent Box-root Padding-all--8">
|
||||
<span className="db-ListViewItem-text Text-color--inherit Text-display--inline Text-fontSize--14 Text-fontWeight--regular Text-lineHeight--20 Text-typeface--base Text-wrap--wrap">
|
||||
<div className="Box-root"><span>{ subscriber.statusPageId != undefined && subscriber.statusPageId != null && subscriber.statusPageId.title || 'Dashboard' }</span></div>
|
||||
<div className="Box-root"><span>{ subscriber.statusPageId !== undefined && subscriber.statusPageId !== null && subscriber.statusPageId.title || 'Dashboard' }</span></div>
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
@@ -45,7 +45,7 @@ if (!isServer) {
|
||||
apiUrl = env('BACKEND_HOST');
|
||||
dashboardUrl = env('HOST');
|
||||
accountsUrl = env('ACCOUNTS_HOST');
|
||||
domain = 'host';
|
||||
domain = '.fyipe.com';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import RenderIfSubProjectAdmin from '../components/basic/RenderIfSubProjectAdmin
|
||||
import { mapCriteria } from '../config';
|
||||
|
||||
class MonitorView extends React.Component {
|
||||
|
||||
// eslint-disable-next-line
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ export default function monitor(state = INITIAL_STATE, action) {
|
||||
success: true,
|
||||
monitors: state.monitorsList.monitors.map(monitor => {
|
||||
if (monitor._id === action.payload.monitorId) {
|
||||
monitor.subscribers.subscribers = monitor.subscribers.subscribers.filter(subscriber => subscriber._id != action.payload._id)
|
||||
monitor.subscribers.subscribers = monitor.subscribers.subscribers.filter(subscriber => subscriber._id !== action.payload._id)
|
||||
monitor.subscribers.count = monitor.subscribers.count - 1
|
||||
return monitor;
|
||||
} else {
|
||||
|
||||
@@ -114,7 +114,7 @@ export default function subscriber(state = initialState, action) {
|
||||
},
|
||||
subscribers: {
|
||||
...state.subscribers,
|
||||
subscribers: state.subscribers.subscribers.filter(subscriber=>subscriber != action.payload._id)
|
||||
subscribers: state.subscribers.subscribers.filter(subscriber=>subscriber !== action.payload._id)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ spec:
|
||||
value: "true"
|
||||
- name: HOST
|
||||
value: "https://staging-accounts.fyipe.com"
|
||||
- name: ACCOUNTS_HOST
|
||||
- name: DASHBOARD_HOST
|
||||
value: "https://staging-dashboard.fyipe.com"
|
||||
- name: BACKEND_HOST
|
||||
value: "https://staging-api.fyipe.com"
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true,
|
||||
"commonjs": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"sourceType": "module",
|
||||
@@ -11,7 +15,7 @@
|
||||
],
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"windows"
|
||||
"unix"
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
|
||||
@@ -2,38 +2,97 @@
|
||||
|
||||
const program = require('commander');
|
||||
const { prompt } = require('inquirer');
|
||||
const {
|
||||
authenticateUser
|
||||
} = require('./src/logic');
|
||||
const { authenticateUser, pingServer } = require('./src/server-monitor');
|
||||
|
||||
program
|
||||
.version('0.0.1', '-v, --version')
|
||||
.description('Fyipe Monitoring Shell');
|
||||
|
||||
program
|
||||
.option('-p, --project-id [projectId]', 'Use Project ID from dashboard')
|
||||
.option('-a, --api-key [apiKey]', 'Use API key from dashboard')
|
||||
.option('-m, --monitor-id [monitorId]', 'Use monitor ID dashboard')
|
||||
.parse(process.argv);
|
||||
|
||||
// Questions to get projectId and API key
|
||||
const questions = [
|
||||
{
|
||||
type: 'input',
|
||||
name: 'projectId',
|
||||
message: 'What is your project Id?'
|
||||
message: 'What is your Project ID?'
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'apiKey',
|
||||
message: 'What is your project\'s API key?'
|
||||
message: 'What is your Project\'s API key?'
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
name: 'monitorId',
|
||||
message: 'What is your Monitor ID?'
|
||||
}
|
||||
];
|
||||
|
||||
program
|
||||
.version('0.0.1')
|
||||
.description('Fyipe Monitoring Shell');
|
||||
checkParams(questions)
|
||||
.then(values => {
|
||||
const [projectId, apiKey, monitorId] = values;
|
||||
|
||||
program
|
||||
.command('start')
|
||||
.alias('s')
|
||||
.description('Authenticates a user by accepting and confirming projectId and apiKey.' +
|
||||
'Begin server monitoring')
|
||||
.action(() => {
|
||||
prompt(questions).then(input => {
|
||||
const { projectId, apiKey } = input;
|
||||
authenticateUser(projectId, apiKey)
|
||||
})
|
||||
})
|
||||
authenticateUser(projectId, apiKey, monitorId)
|
||||
.then(data => {
|
||||
if (monitorId === null) {
|
||||
if (data !== null && data.data !== null && data.data.length > 0) {
|
||||
const question = questions.filter(param => param.name === 'monitorId');
|
||||
question[0].choices = data.data.map(monitor => `${monitor._id} (${monitor.name})`);
|
||||
|
||||
program.parse(process.argv);
|
||||
prompt(question).then(({ monitorId }) => {
|
||||
const _id = monitorId.split(' (').shift();
|
||||
const filteredData = data.data.filter(monitor => monitor._id === _id);
|
||||
|
||||
pingServer(filteredData.pop(), projectId, apiKey).start();
|
||||
});
|
||||
} else {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('You do not have any Server Monitor.');
|
||||
}
|
||||
} else {
|
||||
pingServer(data, projectId, apiKey).start();
|
||||
}
|
||||
})
|
||||
// eslint-disable-next-line no-console
|
||||
.catch(error => { console.error(error) });
|
||||
});
|
||||
|
||||
function checkParams(params) {
|
||||
const values = [];
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
return new Promise(resolve => {
|
||||
resolve(params.reduce((promiseChain, param) => (
|
||||
promiseChain.then(() => (
|
||||
getParamValue(params, param.name).then(value => {
|
||||
values.push(value);
|
||||
|
||||
return values;
|
||||
})
|
||||
))
|
||||
// eslint-disable-next-line no-undef
|
||||
), Promise.resolve()));
|
||||
});
|
||||
}
|
||||
|
||||
function getParamValue(params, name) {
|
||||
// eslint-disable-next-line no-undef
|
||||
return new Promise(resolve => {
|
||||
if (program[name] === true || program[name] === undefined) {
|
||||
if (name === 'monitorId') {
|
||||
resolve(null);
|
||||
} else {
|
||||
prompt(params.filter(param => param.name === name)).then(values => {
|
||||
resolve(values[name]);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
resolve(program[name]);
|
||||
}
|
||||
});
|
||||
}
|
||||
5
server-monitor/package-lock.json
generated
5
server-monitor/package-lock.json
generated
@@ -847,6 +847,11 @@
|
||||
"has-flag": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"systeminformation": {
|
||||
"version": "4.14.8",
|
||||
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-4.14.8.tgz",
|
||||
"integrity": "sha512-05wW1YaMBI6LlVtvw2wXQGr0thpX8E0IImYcpbqUiNanfmq8e+V89pDW2L5V/mN8kU37W0VtVySftQ0PwMIXKw=="
|
||||
},
|
||||
"table": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/table/-/table-5.1.1.tgz",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"fyipe": "index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node index -p 5d64d59cae46131619708309 -a 'b02798c0-c898-11e9-9f14-4963dc67e2ab'",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "@twumm",
|
||||
@@ -19,7 +20,8 @@
|
||||
"inquirer": "^6.2.1",
|
||||
"node-cron": "^2.0.3",
|
||||
"os-utils": "0.0.14",
|
||||
"q": "^1.5.1"
|
||||
"q": "^1.5.1",
|
||||
"systeminformation": "^4.14.8"
|
||||
},
|
||||
"keywords": [
|
||||
"fyipe",
|
||||
|
||||
@@ -1,36 +1,27 @@
|
||||
const axios = require('axios');
|
||||
const { apiUrl } = require('./config');
|
||||
|
||||
const postApi = (url, data) => {
|
||||
|
||||
axios({
|
||||
const postApi = (url, data, apiKey) => {
|
||||
return axios({
|
||||
method: 'POST',
|
||||
url: `${apiUrl}/${url}`,
|
||||
data: data
|
||||
headers: { apiKey },
|
||||
data
|
||||
})
|
||||
.then(function (res) {
|
||||
return res
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error(error)
|
||||
});
|
||||
}
|
||||
.then(({ status, data }) => status === 200 ? data : null);
|
||||
};
|
||||
|
||||
// Testing the getAPI
|
||||
const getApi = (url) => {
|
||||
axios({
|
||||
const getApi = (url, apiKey) => {
|
||||
return axios({
|
||||
method: 'GET',
|
||||
url: `${apiUrl}/${url}`
|
||||
url: `${apiUrl}/${url}`,
|
||||
headers: { apiKey }
|
||||
})
|
||||
.then(function (res) {
|
||||
if (res.data === 'Server Error.') console.log('success')
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error(error)
|
||||
});
|
||||
}
|
||||
.then(({ status, data }) => status === 200 ? data : null);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
module.exports = {
|
||||
postApi,
|
||||
getApi
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
// connect to a route at the backend to validate api and projectId
|
||||
// update serverStat model based on the projectId
|
||||
|
||||
const apiUrl = 'http://localhost:3001';
|
||||
const apiUrl = 'http://localhost:3002';
|
||||
|
||||
module.exports = { apiUrl };
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
const os = require('os-utils')
|
||||
const cron = require('cron');
|
||||
const { postApi, getApi } = require('./api');
|
||||
|
||||
const authenticateUser = (projectId, apiKey) => {
|
||||
postApi(`serverMonitor/${projectId}/${apiKey}`)
|
||||
}
|
||||
|
||||
let pingServer = new cron.CronJob('* * * * *', function() {
|
||||
const serverStat = {
|
||||
cpuCount: os.cpuCount()
|
||||
};
|
||||
postApi(`serverPackage/uploadServerData/${projectId}`, serverStat);
|
||||
}, null, false);
|
||||
|
||||
module.exports = {
|
||||
pingServer,
|
||||
authenticateUser
|
||||
}
|
||||
60
server-monitor/src/server-monitor.js
Executable file
60
server-monitor/src/server-monitor.js
Executable file
@@ -0,0 +1,60 @@
|
||||
const si = require('systeminformation');
|
||||
const cron = require('cron');
|
||||
const { getApi, postApi } = require('./api');
|
||||
|
||||
const authenticateUser = (projectId, apiKey, monitorId) => {
|
||||
const url = monitorId !== null
|
||||
? `monitor/${projectId}/monitor/${monitorId}/?type=server-monitor`
|
||||
: `monitor/${projectId}/monitor/?type=server-monitor`;
|
||||
|
||||
return getApi(url, apiKey);
|
||||
};
|
||||
|
||||
const pingServer = (data, projectId, apiKey) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Starting Server Monitor...');
|
||||
|
||||
const monitorId = data._id;
|
||||
|
||||
return new cron.CronJob('* * * * *', () => {
|
||||
// eslint-disable-next-line no-undef
|
||||
Promise.all([
|
||||
si.currentLoad(),
|
||||
si.mem(),
|
||||
si.blockDevices(),
|
||||
si.networkStats(),
|
||||
si.cpuTemperature(),
|
||||
si.cpu(),
|
||||
si.users(),
|
||||
si.networkConnections(),
|
||||
si.vboxInfo()
|
||||
])
|
||||
.then(data => ({
|
||||
load: data[0],
|
||||
memory: data[1],
|
||||
disk: data[2],
|
||||
traffic: data[3],
|
||||
temperature: data[4],
|
||||
resources: data[5],
|
||||
users: data[6],
|
||||
network: data[7],
|
||||
vbox: data[8]
|
||||
}))
|
||||
.then(data => {
|
||||
postApi(`monitor/${projectId}/log/${monitorId}`, { data }, apiKey)
|
||||
.then(data => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(data);
|
||||
})
|
||||
// eslint-disable-next-line no-console
|
||||
.catch(error => { console.error(error) });
|
||||
})
|
||||
// eslint-disable-next-line no-console
|
||||
.catch(error => { console.error(error) });
|
||||
}, null, false);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
authenticateUser,
|
||||
pingServer
|
||||
};
|
||||
Reference in New Issue
Block a user