0.0.2 • Published 11 months ago
alerta-node-client v0.0.2
Alerta Node.js Client
A powerful and easy-to-use Node.js client for the Alerta.io API, enabling seamless integration with Alerta's monitoring and alerting system.
Features
- Full support for Alerta API endpoints
 - Customizable for different environments and user needs
 - Built-in request validation using Joi
 - Detailed error handling and logging
 
Installation
Install the package using npm:
npm install alerta-node-clientUsage
Initialize the Client
import AlertaClient from 'alerta-node-client';
const alertaClient = new AlertaClient({
  endpoint: 'https://api.alerta.io',
  apiKey: 'your-api-key',
});Example: Create an Alert
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);
}Example: Retrieve Alerts
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);
}Error Handling
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"
}API Methods
Alert Management
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
Query Alerts
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
Tagging
tagAlert(alertId, tags)- Add tags to an alertuntagAlert(alertId, tags)- Remove tags from an alert
User Management
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
Heartbeats
sendHeartbeat(data)- Send a heartbeatgetHeartbeat(heartbeatId)- Retrieve a heartbeatlistHeartbeats()- List all heartbeatsdeleteHeartbeat(heartbeatId)- Delete a heartbeat
Blackouts
createBlackout(data)- Create a blackout periodlistBlackouts()- List all blackout periodsdeleteBlackout(blackoutId)- Delete a blackout period
Metrics & Health
getMetrics()- Get application metricshealthcheck(type)- Perform a health checkgetManifest()- Retrieve build information
Tags & Services
listTags(queryParams)- List tagslistServices(queryParams)- List serviceslistEnvironments(queryParams)- List environments
Contributing
Contributions are welcome! Submit issues or pull requests for bugs and enhancements.
License
This project is licensed under the MIT License - see the LICENSE file for details.
0.0.2
11 months ago