A powerful and easy-to-use Node.js client for the Alerta.io API, enabling seamless integration with Alerta's monitoring and alerting system.
- Full support for Alerta API endpoints
- Customizable for different environments and user needs
- Built-in request validation using Joi
- Detailed error handling and logging
Install the package using npm:
npm install alerta-node-clientimport AlertaClient from 'alerta-node-client';
const alertaClient = new AlertaClient({
endpoint: 'https://api.alerta.io',
apiKey: 'your-api-key',
});const alertData = {
resource: 'web-server',
event: 'CPU_Usage_High',
environment: 'Production',
severity: 'major',
service: ['web'],
group: 'Infrastructure',
value: '90%',
text: 'CPU usage exceeds threshold',
tags: ['critical', 'server'],
attributes: {
ip: '192.168.1.1',
},
};
try {
const response = await alertaClient.createAlert(alertData);
console.log('Alert created:', response);
} catch (error) {
console.error('Error creating alert:', error.message);
}try {
const params = { status: 'open', severity: 'major' };
const alerts = await alertaClient.searchAlerts(params);
console.log('Retrieved alerts:', alerts);
} catch (error) {
console.error('Error retrieving alerts:', error.message);
}Errors include detailed information about the API response:
try {
await alertaClient.getAlert('non-existent-id');
} catch (error) {
console.error(error.message); // Example: "API Error: 404 Not Found"
}createAlert(data)- Create or update an alertgetAlert(alertId)- Retrieve a specific alertsetAlertStatus({ alertId, status, text, timeout })- Update an alert's statusdeleteAlert(alertId)- Delete an alert
searchAlerts(queryParams)- Search for alertslistAlertHistory(queryParams)- Get alert historygetCounts(queryParams)- Count alerts by severity and statusgetTop10Alerts(queryParams, groupBy)- Get top 10 alerts by grouping attribute
tagAlert(alertId, tags)- Add tags to an alertuntagAlert(alertId, tags)- Remove tags from an alert
createUser(name, email, password, text)- Create a userlistUsers()- List all usersupdateUser(userId, data)- Update user detailsupdateUserAttributes(userId, attributes)- Update user attributesupdateMeAttributes(attributes)- Update logged-in user attributesdeleteUser(userId)- Delete a user
sendHeartbeat(data)- Send a heartbeatgetHeartbeat(heartbeatId)- Retrieve a heartbeatlistHeartbeats()- List all heartbeatsdeleteHeartbeat(heartbeatId)- Delete a heartbeat
createBlackout(data)- Create a blackout periodlistBlackouts()- List all blackout periodsdeleteBlackout(blackoutId)- Delete a blackout period
getMetrics()- Get application metricshealthcheck(type)- Perform a health checkgetManifest()- Retrieve build information
listTags(queryParams)- List tagslistServices(queryParams)- List serviceslistEnvironments(queryParams)- List environments
Contributions are welcome! Submit issues or pull requests for bugs and enhancements.
This project is licensed under the MIT License - see the LICENSE file for details.