### Install Miniforge Environment Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/training/setup.md Downloads and installs the Miniforge distribution to manage project dependencies. It also disables automatic base environment activation for a cleaner setup. ```bash wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" bash Miniforge3-$(uname)-$(uname -m).sh conda config --set auto_activate_base false ``` -------------------------------- ### Launch PANIC UI Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/training/setup.md Activates the workshop environment and starts the PANIC user interface. ```bash conda activate panic-workshop export TANGO_HOST={your_host_ip}:10000 panic& ``` -------------------------------- ### Setup Conda Environment Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/training/setup.md Creates a new Conda environment from the provided YAML configuration file and activates it for the workshop. ```bash conda env create -f setup/panic-training.yml conda activate panic-workshop ``` -------------------------------- ### Start PyAlarm Device Server Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/UseEventsWithTaurus.md Starts the specified PyAlarm device server on a target host using the Astor utility from the fandango library. ```python import fandango as fn fn.Astor('test/pyalarm/events').start_servers(host='your_hostname') ``` -------------------------------- ### Launch PANIC UI Source: https://gitlab.com/tango-controls/panic/-/blob/master/panic/test/tests.rst Starts the PANIC graphical user interface in the background. This allows for visual monitoring and interaction with the test devices. ```bash python panic/gui/gui.py & ``` -------------------------------- ### Creating a Time-Triggered Clock Alarm with PyAlarm Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/CustomAlarms.md Provides a step-by-step guide to creating a clock alarm that triggers based on time intervals. It covers adding a new PyAlarm device, defining the alarm formula, starting the device server, and configuring its properties for polling and auto-reset. ```python import fandango as fn fn.tango.add_new_device('PyAlarm/Clock','PyAlarm','test/pyalarm/clock') ``` ```python from panic import AlarmAPI alarms = AlarmAPI() alarms.add(device='test/pyalarm/clock',tag='CLOCK',formula='NOW()%10<5') ``` ```python import fandango as fn fn.Astor('test/pyalarm/clock').start_servers(host='your_hostname') ``` ```python dtest = alarms.devices['test/pyalarm/clock'] dtest.get_config() dtest.config['Enabled'] = 1 dtest.config['AutoReset'] = 1 dtest.config['AlarmThreshold'] = 1 dtest.config['PollingPeriod'] = 1 alarms.put_db_properties(dtest.name,dtest.config) dtest.init() ``` -------------------------------- ### Setup Telegram Notifications (Python) Source: https://context7.com/tango-controls/panic/llms.txt Guides through configuring Telegram bot integration for alarm notifications, including setting up the bot token and adding alarms with Telegram receivers. ```python import fandango as fn import panic # 1. Create a Telegram bot via @BotFather # 2. Get your bot token (format: NNNN:YOURBOTTOKEN) # 3. Get user/chat ID via @userinfobot or bot API # Configure PyAlarm with Telegram bot token device = 'lab/ct/alarms' fn.tango.put_device_property(device, 'TGConfig', 'YOUR_BOT_TOKEN_HERE') alarms = panic.api() alarms.add( device=device, tag='CRITICAL_TG_ALERT', formula='LAB/CT/Critical/Status == FAULT', description='Critical system failure - immediate attention required', receivers='TG:123456789,TG:987654321,operator@facility.com', # Multiple TG recipients severity='ERROR' ) # Test the Telegram notification # The bot will send messages like: # "CRITICAL_TG_ALERT: Critical system failure - immediate attention required # Activated at: Mon Jan 15 10:30:00 2024" ``` -------------------------------- ### PyAlarm Device Server Configuration Example Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/PyAlarmUserGuide.md This Python code snippet demonstrates the typical properties for a PyAlarm device server, including alarm descriptions, receivers, alarm list definitions, polling periods, and SMS configuration. ```python #--------------------------------------------------------- # SERVER PyAlarm/AssemblyArea, PyAlarm device declaration #--------------------------------------------------------- PyAlarm/AssemblyArea/DEVICE/PyAlarm: "LAB/VC/Alarms" # --- LAB/VC/Alarms properties LAB/VC/Alarms->AlarmDescriptions: "OVENPRESSURE:The pressure in the Oven exceeds Range",\ "ADIXENPRESSURE:The pressure in the Roughing Station exceeds Range",\ "OVENTEMPERATURE:The Temperature of the Oven exceeds Range",\ "DEBUG:Just for debugging purposes" LAB/VC/Alarms->AlarmReceivers: OVENPRESSURE:somebody@cells.es,someone_else@cells.es,SMS:+34999666333,\ ADIXENPRESSURE:somebody@cells.es,someone_else@cells.es,SMS:+34999666333,\ OVENTEMPERATURE:somebody@cells.es,someone_else@cells.es,SMS:+34999666333,\ DEBUG:somebody@cells.es LAB/VC/Alarms->AlarmsList: "OVENPRESSURE:LAB/VC/BestecOven-1/Pressure_mbar > 5e-4",\ "OVENRUNNING:LAB/VC/BestecOven-1/MaxValue > 70",\ "ADIXENPRESSURE:LAB/VC/Adixen-01/P1 > 1e-4 and OVENRUNNING",\ "OVENTEMPERATURE:LAB/VC/BestecOven-1/MaxValue > 220",\ "DEBUG:OVENRUNNING and not PCISDOWN" LAB/VC/Alarms->PollingPeriod: 30 LAB/VC/Alarms->SMSConfig: ... ``` -------------------------------- ### Launch Tango Docker Simulation Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/training/setup.md Starts the Tango Control System services using Docker Compose. This provides the necessary infrastructure for PANIC to function. ```bash cd setup sudo docker compose up -d --build ``` -------------------------------- ### List Comprehension Examples Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/AlarmExamples.md Provides examples of list comprehensions with the FIND function, demonstrating equivalent expressions for checking if any element matches a condition, negating conditions, and filtering lists. ```python any([s for s in FIND(SR/ID/SCW01/Cooler*Err*)]) ``` ```python any(FIND(SR/ID/SCW01/Cooler*Err*)) ``` ```python any([s==0 for s in FIND(SR/ID/SCW01/Cooler*Err*)]) ``` ```python any(not s for s in FIND(SR/ID/SCW01/Cooler*Err*)]) ``` ```python not all(FIND(SR/ID/SCW01/Cooler*Err*)) ``` ```python [s for s in FIND(SR/ID/SCW01/Cooler*Err*) if not s] ``` -------------------------------- ### Create Alarms via PANIC API Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/InstallPanic.md Example of initializing the PANIC API and adding a new alarm condition that monitors a simulated attribute. ```python import panic alarms = panic.api() alarms.add('TEST_ALARM',formula='(test/sim/1/A%15 > 5)',description='test',receivers='your@mail') ``` -------------------------------- ### Test PyAlarm Installation Performance Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/PyAlarmTuning.md This script checks the current performance of PyAlarm devices. It requires setting the TANGO_HOST environment variable before execution. The 'check' argument initiates the performance evaluation. ```bash > TANGO_HOST=your_hostname:10000 python panic/extra/report.py check ``` -------------------------------- ### Using the GROUP Macro Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/AlarmsHierarchy.md Examples of using the GROUP macro to aggregate multiple alarms, including basic usage and conditional evaluation. ```default GROUP(ALARM1, ALARM2, ALARM3) GROUP(LOCAL_ALARM1,t01:10000/an/alarm/dev/ALARM2) GROUP(LOCAL_ALARM1,t01:10000/an/alarm/dev/ALARM2;x>=1) GROUP(bl09/vc/vgct-*/p[12];x>1e-5) ``` -------------------------------- ### Browse and Search Alarms Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/PanicAPI.md Demonstrates how to search for alarms by tag, device, attribute, or receiver using the get method. ```python alarms.get(device='boreas') alarms.get(receiver='eshraq') print(alarms['RF_LOST_MKS'].receivers) ``` -------------------------------- ### GET /api/alarms Source: https://context7.com/tango-controls/panic/llms.txt Initializes the AlarmAPI and retrieves configured alarms from the TANGO system. ```APIDOC ## GET /api/alarms ### Description Initializes the PANIC AlarmAPI to access configured alarms. Supports optional filtering by device or TANGO host. ### Method GET ### Endpoint /api/alarms ### Parameters #### Query Parameters - **filters** (string) - Optional - Filter pattern for alarms (e.g., 'sr/rf/*') - **tango_host** (string) - Optional - Specific TANGO host address ### Request Example panic.api(filters='sr/rf/*', tango_host='controls01:10000') ### Response #### Success Response (200) - **alarms** (dict) - Dictionary of alarm objects indexed by tag ``` -------------------------------- ### Compose Alarms with Logical Operators Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/training/exercises_guide.md This example shows how to combine multiple individual alarms into a single composed alarm using logical operators like OR. This allows for more complex alerting conditions. ```Tango TG_ALARM = T1_ALARM OR T2_ALARM ``` -------------------------------- ### Add New Alarms Source: https://context7.com/tango-controls/panic/llms.txt Shows how to create new alarms by defining tags, formulas, and notification receivers. Includes examples for standard alarms, state-dependent alarms, automated actions, and Telegram notifications. ```python import panic alarms = panic.api() # Add a simple pressure alarm alarms.add( tag='HIGH_PRESSURE', device='lab/vc/alarms', formula='LAB/VC/Gauge-01/Pressure > 1e-4', description='Vacuum pressure exceeds safe threshold', receivers='operator@facility.com,SMS:+34666555444', severity='ALARM' ) # Add an alarm that depends on device state alarms.add( tag='DEVICE_FAULT', device='lab/ct/alarms', formula='LAB/CT/PLC-01 == FAULT', description='PLC controller is in FAULT state', receivers='controls@facility.com', severity='ERROR' ) # Add an alarm with ACTION receiver for automated response alarms.add( tag='AUTO_RESPONSE_ALARM', device='lab/ct/alarms', formula='LAB/CT/Sensor-01/Value > 100', description='Sensor value exceeded - triggering safety procedure', receivers='ACTION(alarm:command,lab/ct/safety/Shutdown)', severity='ALARM' ) # Add alarm with Telegram notification alarms.add( tag='CRITICAL_ALERT', device='lab/ct/alarms', formula='LAB/CT/Critical/Status != OK', description='Critical system alert', receivers='TG:123456789,operator@facility.com', severity='ERROR' ) ``` -------------------------------- ### Triggering Actions from PyAlarm Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/ReceiversLoggingAndActions.md Examples of using the ACTION receiver to send emails, reset alarms, reload devices, or write Tango attributes based on alarm events. ```default %SENDMAIL:ACTION(alarm:command,lab/ct/alarms/SendMail,$DESCRIPTION,$ALARM,address@mail.com) %RESET:ACTION(alarm:command,test/pyalarm/logfile/resetalarm,'TEST','$NAME_$DATE_$DESCRIPTION') %INITLOG:ACTION(alarm:command,test/pyalarm/logfile/init) %WRITE:ACTION(alarm:attribute,sys/tg_test/1/string_scalar,'$NAME_$DATE_$VALUES') %LOG:ACTION(alarm:command,controls02:10000/test/folder/tmp-folderds/SaveText,'$NAME_$DATE_$MESSAGE.txt','$REPORT') ``` -------------------------------- ### Python: Generating Clock Signals with NOW() Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/AlarmExamples.md Generates a clock signal using the NOW() function for more accurate interval switching. This example creates a switch every second by checking if the current second modulo 2 is less than 1. It also sets the PollingPeriod and AlarmThreshold. ```python CLOCK = NOW()%2<1 PollingPeriod=1 AlarmThreshold-1 ``` -------------------------------- ### Python: Grouping Alarms with Logical Operators Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/AlarmExamples.md Demonstrates how to group multiple Tango alarms into a single logical alarm using Python. It shows examples of using 'or' for simple combinations and 'any' for more complex scenarios, including pattern matching with FIND. Declared alarms become PyAlarm attributes and variables. ```python ALARM_1: just/my/tango/attribute_1 ALARM_2: just/my/tango/attribute_2 ``` ```python ALARM_1_OR_2: ALARM_1 or ALARM_2 ``` ```python ALARM_1_OR_2: any(( ALARM_1 , ALARM_2 )) ``` ```python ALARM_ANY: any( FIND(my/alarm/device/ALARM_*) ) ``` ```python GROUP(my/alarm/device/ALARM_[12]) ``` -------------------------------- ### Define Alarm on Attribute Quality Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/training/exercises_guide.md This example demonstrates creating an alarm based on the quality status of a device attribute. The alarm will trigger if the attribute's quality indicates an error or bad status. ```Tango T2_ALARM = my/plc/02/Temperature.ALARM ``` -------------------------------- ### Default: Configuration for Clock Signal Generation Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/AlarmExamples.md Provides example configuration values for PollingPeriod, AlarmThreshold, and AutoReset to generate a square signal for testing alarm behavior. These parameters regulate the duty cycle and accuracy of the generated signal. ```default PollingPeriod = 0.1 AlarmThreshold = 50 AutoReset = 0.0001 ``` -------------------------------- ### Clone and Initialize Repository Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/training/setup.md Clones the specific training branch of the PANIC repository and navigates to the training directory. ```bash git clone -b training https://gitlab.com/tango-controls/panic cd panic/doc/training/ ``` -------------------------------- ### Enable Search, Expression Matching, and List Comprehensions Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/AlarmExamples.md Demonstrates using the FIND function with wildcards to search for devices and attributes, combined with list comprehensions and quality checks to trigger alarms based on search results. ```python any([ATTR_ALARM==s.quality for s in FIND('dom/fam/*/pressure')]) ``` ```python any([ATTR_ALARM==QUALITY(s) for s in FIND('dom/fam/*/pressure')]) ``` -------------------------------- ### Launcher Script for Alarms GUI Source: https://gitlab.com/tango-controls/panic/-/blob/master/panic/gui/README.txt This script sets up the necessary environment variables, specifically PYTHONPATH, to include the application's dependencies like Panic API, PyAlarm, and Taurus. It then navigates to the application directory and executes the main GUI script. Ensure the paths are correctly set for your environment. ```shell #!/bin/sh export PYTHONPATH=/path/to/server:/path/to/API:/path/to/taurus:$PYTHONPATH cd /path/to/panic_gui/ /usr/bin/python gui.py ``` -------------------------------- ### Create Clock and Periodic Alarms (Python) Source: https://context7.com/tango-controls/panic/llms.txt Illustrates setting up time-based alarms, including periodic toggling, daily checks, and hourly conditional checks, using panic.api() and fandango. ```python import panic import fandango as fn # Create a PyAlarm device for clock alarms fn.tango.add_new_device('PyAlarm/Clock', 'PyAlarm', 'test/pyalarm/clock') alarms = panic.api() # Add a clock alarm that toggles every 5 seconds alarms.add( device='test/pyalarm/clock', tag='CLOCK_5SEC', formula='NOW() % 10 < 5', description='Clock signal - 5 second cycle', receivers='file:/tmp/clock.log' ) # Configure for fast response device = alarms.devices['test/pyalarm/clock'] device.put_property('PollingPeriod', '1') # Check every second device.put_property('AlarmThreshold', '1') # Trigger immediately device.put_property('AutoReset', '1') # Reset after 1 second device.init() # Daily maintenance check (triggers at 6 AM) alarms.add( device='test/pyalarm/clock', tag='DAILY_CHECK', formula='(NOW() % 86400) > 21600 and (NOW() % 86400) < 21660', # 6:00-6:01 AM description='Daily system health check trigger', receivers='ACTION(alarm:command,sys/health/checker/RunDailyCheck)' ) # Periodic self-reset alarm with condition alarms.add( device='lab/ct/alarms', tag='PERIODIC_PRESSURE_CHECK', formula='(LAB/VC/Gauge-01/Pressure > 1e-5) and ((NOW() % 3600) < 300)', description='Hourly pressure check (first 5 minutes of each hour)', receivers='operator@facility.com' ) ``` -------------------------------- ### Configure Alarm Logging Methods Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/ReceiversLoggingAndActions.md Demonstrates how to set local and remote log file paths using variable substitution for alarm metadata. ```default LogFile = /tmp/pyalarm/$NAME_$DATE_$MESSAGE.log # Remote logging via FolderDS LogFile = tango://sys/folder/panic-logs/$NAME_$DATE_$MESSAGE.log # Combined local and remote logging AlarmReceivers = ACTION(alarm:command,controls02:10000/test/folder/tmp-folderds/SaveText, '$NAME_$DATE_$MESSAGE.txt','$REPORT') ``` -------------------------------- ### Configure and Verify Tango Connection Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/training/setup.md Sets the TANGO_HOST environment variable to point to the local simulation and launches the Jive tool to verify the connection to the Tango database. ```bash export TANGO_HOST=localhost:10000 conda activate panic-workshop jive& ``` -------------------------------- ### Create Periodic Self-Reset Alarm Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/AlarmExamples.md Shows how to create a periodic alarm that resets itself. The example uses a combination of time checks and a self-reset mechanism within the formula. ```python PERIODIC:(FrontEnds/VC/Elotech-01/Temperature and FrontEnds/VC/VGCT-01/P1 \ and (1920<(now%3600)<3200)) or (ResetAlarm('PERIODIC') and False) ``` -------------------------------- ### Initialize PANIC Alarm API Source: https://context7.com/tango-controls/panic/llms.txt Demonstrates how to initialize the PANIC API, including loading all alarms, applying filters, and connecting to specific Tango hosts. It also shows how to iterate through the loaded alarms using a dictionary-like interface. ```python import panic # Initialize the API with default settings (loads all alarms) alarms = panic.api() # Initialize with filters to load only specific alarms alarms = panic.api(filters='sr/rf/*') # Initialize for a specific Tango host alarms = panic.api(tango_host='controls01:10000') # Access alarms like a dictionary print(f"Total alarms loaded: {len(alarms)}") for tag in alarms.keys(): alarm = alarms[tag] print(f"{tag}: {alarm.device} - {alarm.formula}") ``` -------------------------------- ### Configure Global Receivers and Admin Access (Python) Source: https://context7.com/tango-controls/panic/llms.txt Explains how to set system-wide notification rules using global receivers and configure administrative users who have full control over alarms. ```python import fandango as fn # Set global receivers (applied to all alarms matching pattern) # Format: pattern:receivers (pattern can include ! for exclusion) fn.tango.put_property('PANIC', 'GlobalReceivers', [ '.*:oncall@facility.com', # All alarms 'CRITICAL_*:supervisor@facility.com', # Critical alarms only '!DEBUG_*,!TEST_*:sms-gateway@facility.com', # Exclude debug/test from SMS ]) # Configure admin users who can modify any alarm fn.tango.put_property('PANIC', 'PanicAdminUsers', [ 'admin', 'operator', 'controls-team' ]) ``` -------------------------------- ### Initialize PyAlarm Device and Add Event-Based Alarm Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/UseEventsWithTaurus.md Creates a new PyAlarm device instance and registers a new alarm using a formula based on a Tango attribute. Requires the fandango library and an existing Tango environment. ```python import fandango as fn fn.tango.add_new_device('PyAlarm/events','PyAlarm','test/pyalarm/events') from panic import AlarmAPI alarms = AlarmAPI() alarms.add(device='test/pyalarm/events',tag='EVENTS',formula='test/pyalarm/clock/clock') ``` -------------------------------- ### Launch PyAlarm Devices with screen Source: https://gitlab.com/tango-controls/panic/-/blob/master/panic/test/tests.rst Launches multiple PyAlarm instances in detached screen sessions. Each instance is configured to monitor specific aspects like Actions, Clock, Delay, etc., with a verbosity level of 2. ```bash INSTANCES="Actions Clock Delay exceptions Group Quality results Value" for i in $INSTANCES; do screen -dm -S $i python panic/ds/PyAlarm.py $i -v2; done ``` -------------------------------- ### Define Alarm on Aggregated Values Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/training/exercises_guide.md This example shows how to define an alarm based on an aggregated value, such as the maximum value found across multiple device attributes. It checks if the maximum temperature exceeds a threshold. ```Tango TMax_ALARM = max( FIND( */plc/*/Temperature )) ) > 45 ``` -------------------------------- ### Download PANIC System Components Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/InstallPanic.md Commands to check out the required Fandango library, PyAlarm device server, and the PANIC user interface from the Tango Controls SVN repository. ```shell svn co https://tango-cs.svn.sourceforge.net/svnroot/tango-cs/share/fandango/trunk/fandango fandango svn co https://svn.code.sf.net/p/tango-ds/code/DeviceClasses/SoftwareSystem/PyAlarm/trunk svn co https://svn.code.sf.net/p/tango-ds/code/Clients/python/Panic/trunk ``` -------------------------------- ### Register PANIC Devices in Tango Database Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/InstallPanic.md Python script using PyTango to add new device instances to the Tango database, including a PyAlarm device and a signal simulator for testing. ```python import PyTango db = PyTango.Database() def add_new_device(server,klass,device): dev_info = PyTango.DbDevInfo() dev_info.name = device dev_info.klass = klass dev_info.server = server get_database().add_device(dev_info) add_new_device('PyAlarm/1','PyAlarm','test/alarms/1') add_new_device('PySignalSimulator/1','PySignalSimulator','test/sim/1') db.put_device_property('test/sim/1',{'DynamicAttributes':['A=t%100']}) ``` -------------------------------- ### Define Alarm Formulas Source: https://context7.com/tango-controls/panic/llms.txt Examples of alarm formulas using Python expressions and Tango attribute references. These formulas support state checks, timestamp comparisons, quality checks, and complex logic using macros like GROUP and FIND. ```text "LAB/VC/Gauge-01/Pressure > 1e-4" "LAB/CT/PLC-01 == FAULT" "?LAB/CT/PLC-01 and LAB/CT/PLC-01/Temperature > 100" "LAB/CT/Sensor/Value.value > 50" "LAB/CT/Sensor/Value.time < (now - 60)" "LAB/CT/Sensor/Temperature.quality == ATTR_ALARM" "LAB/CT/Valve/Position.delta == -1" "LAB/CT/Device/MissingAttr.exception" "any(FIND(LAB/VC/*/Pressure) > 1e-4)" "(LAB/VC/Pump-01/Status != ON) and (LAB/VC/Gauge-01/Pressure > 1e-3)" "ALARM_A or ALARM_B" "GROUP(my/alarm/device/ALARM_*)" "NOW() % 3600 < 300" ``` -------------------------------- ### PyAlarm Mail Message Format Example Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/PyAlarmUserGuide.md This Python code snippet illustrates the format of an alarm message sent via email by PyAlarm, including subject, date, alarm tag, details, receivers, and lists of other active and past alarms. ```python Subject: LAB/VC/Alarms: Alarm RECOVERED (OVENTEMPERATURE) Date: Wed, 12 Nov 2008 11:52:39 +0100 TAG: OVENTEMPERATURE LAB/VC/BestecOven-1/MaxValue > 220 was RECOVERED at Wed Nov 12 11:52:39 2008 Alarm receivers are: somebody@cells.es someone_else@cells.es Other Active Alarms are: DEBUG:Fri Nov 7 18:37:35 2008:OVENRUNNING and not PCISDOWN OVENRUNNING:Fri Nov 7 18:37:17 2008:LAB/VC/BestecOven-1/MaxValue > 70 Past Alarms were: OVENTEMPERATURE:Fri Nov 7 20:49:46 2008 ``` -------------------------------- ### Launch Simulator with screen Source: https://gitlab.com/tango-controls/panic/-/blob/master/panic/test/tests.rst Launches the SimulatorDS in detached screen mode. It takes the PANIC test configuration and a verbosity level as arguments. ```bash screen -dm -S simulator python SimulatorDS/SimulatorDS.py panic-test -v2 ``` -------------------------------- ### Accessing PyAlarm CACHE for Value Analysis Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/CustomAlarms.md Shows how to access the PyAlarm CACHE dictionary, which stores the last values of tango attributes used in formulas. Examples include filtering values equal to zero and checking for variations in cached values. ```python PASS_BY_0=[(k,v.time.tv_sec,str(v.value)) for k,t in CACHE.items() for v in t if v.value==0] ``` ```python not (lambda l:max(l)-min(l))([v.value for v in CACHE['wr/rf/circ-1/heartbeat']]) ``` -------------------------------- ### Manage Alarm Administration and User Filters Source: https://context7.com/tango-controls/panic/llms.txt Demonstrates how to retrieve authorized administrators for specific alarms and manage saved search filters for the GUI interface. ```python import panic alarms = panic.api() admins = alarms.get_admins_for_alarm('HIGH_PRESSURE') print(f"Authorized users: {admins}") alarms.set_user_filters({ 'Vacuum System': {'device': 'vacuum', 'severity': 'WARNING'}, 'Critical Only': {'severity': 'ERROR'}, 'My Alarms': {'receivers': 'myuser@facility.com'} }) filters = alarms.get_user_filters() ``` -------------------------------- ### Export and Import Alarms (Python) Source: https://context7.com/tango-controls/panic/llms.txt Shows how to export alarm configurations to CSV or dictionary formats for backup and import alarms from CSV files using the panic.api(). ```python import panic import json alarms = panic.api() # Export alarms to CSV file alarms.export_to_csv( filename='/tmp/alarm_backup.csv', regexp='LAB/*', # Optional filter states=True # Include current active state ) # Export to dictionary (useful for JSON serialization) data = alarms.export_to_dict( regexp='LAB/*', config=True, # Include device configuration states=True # Include current states ) # data = {'alarms': {...}, 'devices': {...}} with open('/tmp/alarms.json', 'w') as f: json.dump(data, f, indent=2) # Import alarms from CSV # CSV format: TAG,DEVICE,FORMULA,DESCRIPTION,RECEIVERS,SEVERITY new_alarms = alarms.load_from_csv('/tmp/new_alarms.csv', write=True) print(f"Imported {len(new_alarms)} alarms") # Export device configurations alarms.export_configurations('/tmp/device_configs.csv', regexp='lab/*') # Import device configurations alarms.load_configurations('/tmp/device_configs.csv') ``` -------------------------------- ### Defining and Combining Alarms Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/GroupAlarms.md Demonstrates how to assign attributes to alarm variables and combine them using logical operators or pattern matching. These expressions allow for efficient alarm evaluation without redundant attribute reads. ```text ALARM_1: just/my/tango/attribute_1 ALARM_2: just/my/tango/attribute_2 ALARM_1_OR_2: ALARM_1 or ALARM_2 ALARM_1_OR_2: any(( ALARM_1 , ALARM_2 )) ALARM_ANY: any( FIND(my/alarm/device/ALARM_*) ) ``` -------------------------------- ### Logging configuration Source: https://context7.com/tango-controls/panic/llms.txt Configure logging settings for the alarm system. ```APIDOC ## Logging Configuration ### Description Configure the logging behavior of the alarm system, including log file location and snapshot usage. ### Method `fn.tango.put_device_property(device, property_name, value)` ### Endpoint N/A (Device Property Configuration) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python fn.tango.put_device_property(device, 'LogFile', '/var/log/panic/$NAME.log') fn.tango.put_device_property(device, 'UseSnap', 'True') ``` ### Response N/A (This is a configuration function, not a direct API response) ``` -------------------------------- ### Send Test Message on Startup Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/AlarmExamples.md A simple alarm formula that is always true, triggering an email notification upon system startup. It uses specific directives for debugging messages and recipient addresses. ```python AlarmList -> DEBUG:True AlarmDescriptions -> DEBUG:The PyAlarm Device $NAME has been restarted AlarmReceivers -> DEBUG: test@tester.com ``` -------------------------------- ### Load CSV Configuration with fandango Source: https://gitlab.com/tango-controls/panic/-/blob/master/panic/test/tests.rst Loads a CSV file containing test device configurations using the fandango utility. This is a prerequisite for launching the tests. ```bash csv2tango panic/test/testdevs.csv ``` -------------------------------- ### Defining Alarm Hierarchies Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/AlarmsHierarchy.md Demonstrates how to define alarm dependencies by referencing previous alarm results in formulas, allowing for TOP/BOTTOM filtering. ```default GAB1 = any([t >5 for t in FIND(tc1:10000/LMC/C02/GAB/*)]) GAB2 = any([t >5 for t in FIND(tc1:10000/LMC/C02/GAB/*)]) GAB_ALL= GAB1 or GAB2 OTHER = tc1:10000/LMC/C02/Other/State != ON CAPITAL = GAB_ALL or OTHER ``` -------------------------------- ### Allow System Commands via PyAlarm Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/PyAlarmUserGuide.md Configures the PyAlarm class to permit the execution of specific system commands (e.g., 'beep&'). This is done by listing allowed actions in the 'AllowedActions' property. ```python PyAlarm.AllowedActions: beep& ``` ```python AlarmReceivers: ALARM_TAG: ACTION(alarm:system:beep&) ``` -------------------------------- ### Monitor Alarm States and Lifecycle Source: https://context7.com/tango-controls/panic/llms.txt Explains how to interact with alarm states, perform state transitions, and retrieve detailed diagnostic information for TANGO-controlled alarms. ```python import panic alarms = panic.api() alarm = alarms['MY_ALARM'] state = alarm.get_state() info = alarm.to_dict() # Retrieve bulk states states = alarms.get_states() device_states = alarms.get_states(device='lab/vc/alarms') ``` -------------------------------- ### Initialize PANIC AlarmAPI Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/PanicAPI.md Initializes the PANIC AlarmAPI to interact with registered alarms. ```python import panic alarms = panic.api() ``` -------------------------------- ### Add and Remove Alarms Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/PanicAPI.md Shows how to create a new alarm with specific formula and receivers, and how to remove an existing alarm. ```python alarms.add('RF_ON_FIRE','rf/ct/alarms',formula='rf/ct/plc-01/temperature>1000.',message='FIRE!',receivers='rf@cells.es,plc@cells.es') alarms.remove('RF_ON_FIRE') ``` -------------------------------- ### Configure PyAlarm Device Property Source: https://gitlab.com/tango-controls/panic/-/blob/master/doc/recipes/TelegramSetup.md Set the TGConfig property on the PyAlarm device using the fandango library to store the bot token. ```python fandango.tango.put_device_property('your/device/name','TGConfig','NNNNN:YOURBOTTOKEN') ``` -------------------------------- ### Evaluate PANIC Alarm Formulas Source: https://context7.com/tango-controls/panic/llms.txt Provides functionality to test and evaluate alarm formulas programmatically. Supports direct evaluation, remote evaluation using a specific device, and evaluation with custom local variables. Can also parse attributes used within formulas. Requires the 'panic' library. ```python import panic alarms = panic.api() # Evaluate a formula directly result = alarms.evaluate('LAB/VC/Gauge-01/Pressure > 1e-4') print(f"Condition met: {result}") # Evaluate using a specific PyAlarm device (remote evaluation) result = alarms.evaluate( formula='LAB/VC/Gauge-01/Pressure > 1e-4', device='lab/vc/alarms', timeout=5000 ) # Evaluate with custom local variables result = alarms.evaluate( formula='value > threshold', _locals={'value': 0.001, 'threshold': 0.0005} ) # Parse attributes used in a formula attrs = alarms.parse_attributes('(A/B/C/Value > 10) and (D/E/F/State == ON)') print(attrs) ``` -------------------------------- ### Timing configuration Source: https://context7.com/tango-controls/panic/llms.txt Configure the timing parameters for alarm evaluations and notifications. ```APIDOC ## Timing Configuration ### Description Configure various timing-related properties for the alarm system. ### Method `fn.tango.put_device_property(device, property_name, value)` ### Endpoint N/A (Device Property Configuration) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python fn.tango.put_device_property(device, 'PollingPeriod', '30') fn.tango.put_device_property(device, 'AlarmThreshold', '3') fn.tango.put_device_property(device, 'AutoReset', '60') fn.tango.put_device_property(device, 'Reminder', '3600') fn.tango.put_device_property(device, 'StartupDelay', '30') ``` ### Response N/A (This is a configuration function, not a direct API response) ```