 # pm2-slack-monitor
 
A simple CLI utility to monitor your PM2-managed server processes and automatically send uncaught error logs to Slack channels using incoming webhook URLs

## Features

- Monitors specific PM2 app names
- Sends detailed uncaught error logs and crashes to dedicated Slack channels
-  Saves monitored apps locally in a config file
-  Lightweight and easy-to-use CLI interface
-  Compatible with PM2 process manager
-  Can be run as a background process using PM2

## Installation

1. **Install Package Globally on server:**
   ```bash
   npm i -g pm2-slack-monitor 
   ```
2. **Ensure you have PM2 installed Globally**.

3. **Test Installation with command:**
   ```bash
   pm2-slack-monitor --help
   ```
 - **Example Otuput**
    ```
    Available Commands
    Usage: pm2-slack-monitor [options] [command]
    🛠️ Terminal-based utility to monitor PM2 processes and send Slack alerts.
    Options:
      -V, --version                      output the version number
      -h, --help                         display help for command
    Commands:
      start                              Start monitoring all registered PM2 processes
      add <processName> <slackWebhook>   Add a PM2 process and assign a Slack webhook
      remove <processName>               Remove a process from monitoring
      list                               List all monitored processes with their Slack webhooks
      update <processName> <webhookUrl>  Update Slack webhook for a monitored process
      help [command]                     display help for command
    ```

3. **Add pm2 process to slack monitor:**
   ```bash
   pm2-slack-monitor add <pm2-app-name> <slack-webhook-url>
   ```
- **Example**
    ```
     pm2-slack-monitor add my-app https://hooks.slack.com/services/T00000000/B00000000/xxxxxxxxxx
     ```
   
4. **To update pm2 process webhook url in slack monitor:**
   ```bash
   pm2-slack-monitor update <pm2-app-name> <slack-webhook-url>
   ```
  - **Example**
    ```bash
     pm2-slack-monitor update my-app https://hooks.slack.com/services/T00000000/B00000000/yyyyyyyyyy
     ```
5. **To remove pm2 process  in slack monitor:**
   ```bash
   pm2-slack-monitor remove <pm2-app-name>
   ```
  - **Example**
    ```bash
     pm2-slack-monitor remove my-app 
     ```
 
 6. **To List monitored processes in slack monitor:**
       ```bash
       pm2-slack-monitor list
       ```

7. **To Start monitoring pm2 process with slack monitor:**
   ```bash
   pm2 start "pm2-slack-monitor start" --name "pm2-slack-monitor"
   ```

- This ensures continuous monitoring of your PM2-managed apps, with error logs automatically sent to the configured Slack channels.

## Requirements

- Node.js (v14 or higher)
- PM2 process manager
- A valid Slack incoming webhook URL for each monitored process

## Contributing
- Contributions are welcome! To contribute: Fork the repository. 
- Create a new branch (git checkout -b feature/your-feature).
- Make your changes and commit (git commit -m 'Add your feature').
- Push to the branch (git push origin feature/your-feature).
- Open a Pull Request.

