Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible script monitoring types #2439

Closed
1 task done
danger-dream opened this issue Dec 19, 2022 · 4 comments · May be fixed by #3919
Closed
1 task done

More flexible script monitoring types #2439

danger-dream opened this issue Dec 19, 2022 · 4 comments · May be fixed by #3919
Labels
area:monitor Everything related to monitors feature-request Request for new features to be added question Further information is requested

Comments

@danger-dream
Copy link

⚠️ Please verify that this feature request has NOT been suggested before.

  • I checked and didn't find similar feature request

🏷️ Feature Request Type

Other

🔖 Feature description

Can JavaScript type monitoring be provided?

This function is mainly provided for people who are more professional or have more complex needs

✔️ Solution

  • Can use node:vm to achieve this function

  • Most of the existing functions are encapsulated and injected into the vm context, and the maintainer writes a script to customize the functions they want to achieve in more detail, such as:

  • More flexible http requests..

async function event(m: Monitor): Promise<{ status: boolean, time?: number, msg?: string } | boolean | number> {
	if (!m.params) {
		throw new MonitorError('Invalid parameter')
	}
	// try....
	const { url } = JSON.parse(m.params)
	const res = await utils.axios.get(url)
	if (res.status === 200){
		if (res.data.xxx === 'success') {
			return true
		}
		return { status: false, msg: 'data.xxx is not "success"' }	
	}
	return { status: false, msg: 'status code error..' }
}
  • Sensitive to ping time
async function event(m: Monitor): Promise<{ status: boolean, time?: number, msg?: string } | boolean | number> {
	if (!m.params) {
		throw new MonitorError('Invalid parameter')
	}
	// try....
	const { host } = JSON.parse(m.params)
	const ms = await utils.ping(host)
	if (ms > 60) {
		throw new MonitorError('access too slow')
	}
	return ms
}
  • More interested in something in the result set
async function event(m: Monitor): Promise<{ status: boolean, time?: number, msg?: string } | boolean | number> {
	const st = Date.now()
	if (!m.params) {
		throw new MonitorError('Invalid parameter')
	}
	// try....
	const { databaseConnectionString, databaseQuery } = JSON.parse(m.params)
	const res = await utils.mysqlQuery(this.databaseConnectionString, this.databaseQuery)
	if (res?.length > 0 && res.filter(x => x.user !== 'xxx' && x.age > 10).length > 0) {
		return { status: true, time: Date.now() - st }
	}
	return return { status: false, time: Date.now() - st, msg: 'the desired data was not found' }
}

❓ Alternatives

No response

📝 Additional Context

No response

@danger-dream danger-dream added the feature-request Request for new features to be added label Dec 19, 2022
@alexmaurer-madis
Copy link

Is your proposal in the same spirit of mine but even more integrated ?

Have a look at FR #2431

@danger-dream
Copy link
Author

Yes, our suggestion is similar, but the workload of modifying the existing monitoring code part is a bit heavy, so my suggestion is to add script type monitoring

@CommanderStorm
Copy link
Collaborator

CommanderStorm commented Dec 7, 2023

@danger-dream
given that jsonata based json-query is merged and slow response times are tracked in #4005, is this issue resolved?
Note that generalising these response checks is tracked in #3919

@CommanderStorm CommanderStorm added the question Further information is requested label Dec 7, 2023
@CommanderStorm
Copy link
Collaborator

CommanderStorm commented Feb 11, 2024

is this issue resolved?

Given that @danger-dream did not respond for 2 months, I consider this issue resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:monitor Everything related to monitors feature-request Request for new features to be added question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants