# File-arrival demo: one workflow shows the common automation building blocks. # File Monitor trigger -> event-based start # Linux script -> shell scripts with parameters # SQL task + variable -> a value from a database, kept for later tasks # ${_date(..., -1)} -> date calculations # Web Service task -> REST API call # PowerShell task -> PowerShell on Windows # Stop / Start service -> central control of Windows services # # Before import: change the agents (linux-agent, windows-agent), the database # connection (Demo_Mysql) and the credentials (Controller API, linux-admin). # Run "HUB-DEMO SETUP Workflow" once, then copy a .csv file to /demo/hub_demo/in/. version: 1 style: compact create_only: [business_services, credentials, database_connections] business_services: - HUB-DEMO: File-arrival demo objects scripts: hub_demo_check_file.sh: scriptType: Script description: Checks the file that started the workflow. content: |- #!/bin/bash # $1 = the file that the File Monitor trigger found FILE="$1" echo "File-arrival demo - file check on $(hostname)" echo "File: $FILE" if [ ! -f "$FILE" ]; then echo "ERROR: file not found" exit 1 fi if [ ! -s "$FILE" ]; then echo "ERROR: file is empty" exit 2 fi LINES=$(wc -l < "$FILE") echo "Size : $(stat -c %s "$FILE") bytes" echo "Lines: $LINES" echo "Header: $(head -1 "$FILE")" echo "File is OK" exit 0 hub_demo_setup.sh: scriptType: Script description: Creates the demo folders and a sample file on the Linux agent. Runs as a sudo user, then gives the folders to ubroker. content: |- #!/bin/bash # Setup for the File-arrival demo. Safe to run again. # Runs as a sudo user: sudo creates the folders, then ubroker becomes the owner. BASE=/demo/hub_demo OWNER=ubroker echo "Running as: $(id -un)" if ! sudo -n true 2>/dev/null; then echo "ERROR: $(id -un) cannot use sudo without a password" exit 1 fi sudo mkdir -p "$BASE/in" "$BASE/samples" || exit 1 sudo tee "$BASE/samples/sample.csv" > /dev/null <<'CSV' period,site,item,count CURRENT,Site-A,Orders,124 CURRENT,Site-A,Returns,87 CURRENT,Site-B,Orders,96 CURRENT,Site-B,Invoices,231 CSV sudo chown -R "$OWNER:$(id -gn $OWNER)" "$BASE" || exit 1 sudo chmod -R 775 "$BASE" || exit 1 echo "Demo folders are ready:" ls -ld /demo ls -lR "$BASE" echo echo "To start the demo (trigger enabled), copy the sample into the inbound folder:" echo " cp $BASE/samples/sample.csv $BASE/in/data_\$(date +%Y%m%d%H%M%S).csv" exit 0 hub_demo_report.ps1: scriptType: Data description: Writes a small report with the period and the business date. content: |- param( [string]$Period, [string]$BusinessDate, [string]$SourceFile ) Write-Output "File-arrival demo - PowerShell on $env:COMPUTERNAME" Write-Output "Period name : $Period" Write-Output "Business date : $BusinessDate (today - 1 day)" Write-Output "Source file : $SourceFile" $dir = "C:\demo\hub_demo" New-Item -ItemType Directory -Force -Path $dir | Out-Null $out = Join-Path $dir "report_$BusinessDate.txt" "Period=$Period`r`nBusinessDate=$BusinessDate`r`nSourceFile=$SourceFile`r`nCreated=$(Get-Date -Format s)" | Out-File -FilePath $out -Encoding utf8 Write-Output "Report written: $out" exit 0 tasks: # 1. Event-based trigger: the monitor that the trigger uses HUB-DEMO Watch Inbound File: type: File Monitor agent: linux-agent fileName: /demo/hub_demo/in/*.csv fmtype: Created business_services: [HUB-DEMO] # 2. Linux script: check the file HUB-DEMO 01 Check File (Linux): type: Unix agent: linux-agent commandOrScript: Script script: hub_demo_check_file.sh parameters: ${_resolve('ops_trigger_file_name', '/demo/hub_demo/samples/sample.csv')} outputReturnType: OUTERR outputReturnSline: '1' outputReturnNline: '100' business_services: [HUB-DEMO] # 3. SQL: get the period name, put it in a variable HUB-DEMO 02 Get Period Name (SQL): type: Sql connection: Demo_Mysql sqlCommand: SELECT UPPER(DATE_FORMAT(CURDATE(), '%b-%y')) AS PERIOD_NAME actions: setVariableActions: - status: Success variableName: period_name variableValue: ${_resultsColumn('PERIOD_NAME')} variableScope: Top Level Parent business_services: [HUB-DEMO] # 4. Web Service: call a REST API HUB-DEMO 03 Call REST API: type: Web Service url: https://your-controller.example.com/resources/agents/list httpMethod: GET httpAuth: Basic credentials: Controller API httpHeaders: - Accept: application/json business_services: [HUB-DEMO] # 5. PowerShell on Windows, with the period and the date - 1 day HUB-DEMO 04 PowerShell Report (Windows): type: Windows agent: windows-agent command: powershell -NoProfile -ExecutionPolicy Bypass -File "${_scriptPath('hub_demo_report.ps1')}" -Period "${period_name}" -BusinessDate "${business_date}" -SourceFile "${_resolve('ops_trigger_file_name', 'manual run')}" variables: - business_date: ${_date('yyyy-MM-dd', -1)} outputReturnType: OUTERR outputReturnSline: '1' outputReturnNline: '100' business_services: [HUB-DEMO] # 6. Windows service: stop and start HUB-DEMO 05 Stop Windows Service: type: Windows agent: windows-agent command: powershell -NoProfile -Command "Stop-Service -Name '${win_service}' -Force -ErrorAction Stop; Get-Service -Name '${win_service}' | Format-Table Name, DisplayName, Status -AutoSize" outputReturnType: OUTERR outputReturnSline: '1' outputReturnNline: '100' business_services: [HUB-DEMO] HUB-DEMO 06 Start Windows Service: type: Windows agent: windows-agent command: powershell -NoProfile -Command "Start-Service -Name '${win_service}' -ErrorAction Stop; Get-Service -Name '${win_service}' | Format-Table Name, DisplayName, Status -AutoSize" outputReturnType: OUTERR outputReturnSline: '1' outputReturnNline: '100' business_services: [HUB-DEMO] # Setup: folders and files for the demo HUB-DEMO SETUP Linux Folders: type: Unix agent: linux-agent commandOrScript: Script script: hub_demo_setup.sh credentials: linux-admin outputReturnType: OUTERR outputReturnSline: '1' outputReturnNline: '100' business_services: [HUB-DEMO] HUB-DEMO SETUP Windows Folder: type: Windows agent: windows-agent command: powershell -NoProfile -Command "New-Item -ItemType Directory -Force -Path 'C:\demo\hub_demo' | Out-Null; Get-Item 'C:\demo\hub_demo' | Format-List FullName, CreationTime; Get-Service -Name '${win_service}' | Format-Table Name, DisplayName, Status -AutoSize" outputReturnType: OUTERR outputReturnSline: '1' outputReturnNline: '100' business_services: [HUB-DEMO] HUB-DEMO SETUP Workflow: type: Workflow summary: Creates the folders and the sample file for the File-arrival demo. Run it once before the demo. variables: - win_service: Spooler business_services: [HUB-DEMO] tasks: HUB-DEMO SETUP Linux Folders: position: [60, 120] HUB-DEMO SETUP Windows Folder: position: [60, 260] HUB-DEMO Inbound File Workflow: type: Workflow summary: File-arrival demo - file arrives, Linux, SQL, REST, PowerShell, Windows service. variables: - win_service: Spooler business_services: [HUB-DEMO] tasks: HUB-DEMO 01 Check File (Linux): position: [60, 120] HUB-DEMO 02 Get Period Name (SQL): after: HUB-DEMO 01 Check File (Linux) position: [300, 120] HUB-DEMO 03 Call REST API: after: HUB-DEMO 02 Get Period Name (SQL) position: [540, 120] HUB-DEMO 04 PowerShell Report (Windows): after: HUB-DEMO 03 Call REST API position: [780, 120] HUB-DEMO 05 Stop Windows Service: after: HUB-DEMO 04 PowerShell Report (Windows) position: [1020, 120] HUB-DEMO 06 Start Windows Service: after: HUB-DEMO 05 Stop Windows Service position: [1260, 120] triggers: HUB-DEMO File Arrived: type: File Monitor description: Starts the File-arrival demo workflow when a .csv file arrives in /demo/hub_demo/in. taskMonitor: HUB-DEMO Watch Inbound File tasks: [HUB-DEMO Inbound File Workflow] calendar: System Default business_services: [HUB-DEMO]