Mason10198 / SkywarnPlus

Empowering Asterisk / app_rpt Nodes with Local Alert Intelligence
GNU General Public License v3.0
58 stars 3 forks source link

alerts cleared ' Alertscript ' #103

Closed Leaper54 closed 2 months ago

Leaper54 commented 3 months ago

I am trying to run an AlertScript whenever all alerts are cleared. I understand that because I use wildcards for the alerts, I cannot use ' ClearCommands '. I now tried to use InactiveCommands, but that does not trigger the script either. Any suggestion is appreciated. Question; Does ' INJECT: true ' ( for testing ) trigger the AlertScript?

AlertScript: Enable: true Mappings:

Mason10198 commented 3 months ago

Please enable debugging, clear tmp data, inject your test alerts, clear the alerts, and then upload the log file.

Leaper54 commented 3 months ago

Skytailon.sh AND Skytailoff.sh were not triggered. Both run correctly from the command line. Log attached. SkywarnPlus.log

Mason10198 commented 2 months ago

Unable to reproduce this...

config.yaml I am using to test:

AlertScript:
  Enable: true

  ActiveCommands:
  - Type: BASH
    Commands:
    - echo "THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM ZERO TO NON-ZERO"

  InactiveCommands:
  - Type: BASH
    Commands:
    - echo "THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM NON-ZERO TO ZERO"

DEV:
  INJECT: false
  INJECTALERTS:
   - Title: Heat Advisory

This works as expected. When INJECT is enabled:

2024-07-21 17:39:24,456 DEBUG AlertScript configuration: {'Mappings': [{'Commands': ['/usr/local/bin/SkywarnPlus/SkyDescribe.py "{alert_title}"'], 'Type': 'BASH', 'Triggers': ['Tornado Warning']}], 'Enable': True, 'ActiveCommands': [{'Commands': ['echo "THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM ZERO TO NON-ZERO"'], 'Type': 'BASH'}], 'InactiveCommands': [{'Commands': ['echo "THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM NON-ZERO TO ZERO"'], 'Type': 'BASH'}]}
2024-07-21 17:39:24,457 DEBUG Current active alerts count: 1
2024-07-21 17:39:24,458 INFO Executing Active BASH Command: echo "THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM ZERO TO NON-ZERO"
THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM ZERO TO NON-ZERO

And when INJECT is disabled (alerts cleared):

2024-07-21 17:39:51,874 DEBUG AlertScript configuration: {'Mappings': [{'Type': 'BASH', 'Commands': ['/usr/local/bin/SkywarnPlus/SkyDescribe.py "{alert_title}"'], 'Triggers': ['Tornado Warning']}], 'Enable': True, 'InactiveCommands': [{'Type': 'BASH', 'Commands': ['echo "THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM NON-ZERO TO ZERO"']}], 'ActiveCommands': [{'Type': 'BASH', 'Commands': ['echo "THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM ZERO TO NON-ZERO"']}]}
2024-07-21 17:39:51,875 DEBUG Current active alerts count: 0
2024-07-21 17:39:51,876 INFO Executing Inactive BASH Command: echo "THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM NON-ZERO TO ZERO"
THE NUMBER OF ACTIVE ALERTS JUST CHANGED FROM NON-ZERO TO ZERO

SkywarnPlus appears to be processing the inactive/active state change correctly, even with injected alerts.

Mason10198 commented 2 months ago

Ah, I just noticed that your config is not set up correctly. You have it set up like this:

AlertScript:
Enable: true
Mappings:
- Type: BASH
Commands:
- '/etc/asterisk/scripts/Skytailon.sh'
InactiveCommands:
- '/etc/asterisk/scripts/Skytailoff.sh'
Triggers:
- '*Warning'
- '*Watch'
- '*Advisory'
- '*Statement'

but it needs to be set up like this:

AlertScript:
  Enable: true

  ActiveCommands:
  - Type: BASH
    Commands:
    - '/etc/asterisk/scripts/Skytailon.sh'

  InactiveCommands:
  - Type: BASH
    Commands:
    - '/etc/asterisk/scripts/Skytailoff.sh'

  Mappings:
  # None of this matters for ActiveCommands or InactiveCommands
  - Type: BASH
    Commands:
    - /usr/local/bin/SkywarnPlus/SkyDescribe.py "{alert_title}"
    Triggers:
    - Tornado Warning