diff --git a/.github/workflows/main_swaydevshello(stagingslot).yml b/.github/workflows/main_swaydevshello(stagingslot).yml index 843a880..2036c5d 100644 --- a/.github/workflows/main_swaydevshello(stagingslot).yml +++ b/.github/workflows/main_swaydevshello(stagingslot).yml @@ -60,4 +60,4 @@ jobs: with: app-name: 'swaydevshello' slot-name: 'stagingslot' - publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_7B57368891D74D8FA321093A5BE5C903 }} + publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_7acf3d660e9a4eab85ba98463d240d40 }} diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..d898232 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,87 @@ +# Python to Linux Web App on Azure +# Build your Python project and deploy it to Azure as a Linux Web App. +# Change python version to one thats appropriate for your application. +# https://docs.microsoft.com/azure/devops/pipelines/languages/python + +trigger: +- main + +variables: + # Azure Resource Manager connection created during pipeline creation + azureServiceConnectionId: '84f81cff-9c7a-4e64-a21e-2a77dd18fadc' + + # Web app name + webAppName: 'pythonwebappmahes' + + # Agent VM image name + vmImageName: 'ubuntu-latest' + + # Environment name + environmentName: 'pythonwebappmahes' + + # Project root folder. Point to the folder containing manage.py file. + projectRoot: $(System.DefaultWorkingDirectory) + + # Python version: 3.7 + pythonVersion: "3.8" + +stages: +- stage: Build + displayName: Build stage + jobs: + - job: BuildJob + pool: + name: Default + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '$(pythonVersion)' + displayName: 'Use Python $(pythonVersion)' + + - script: | + python -m venv antenv + source antenv/bin/activate + python -m pip install --upgrade pip + pip install setup + pip install -r requirements.txt + workingDirectory: $(projectRoot) + displayName: "Install requirements" + + - task: ArchiveFiles@2 + displayName: 'Archive files' + inputs: + rootFolderOrFile: '$(projectRoot)' + includeRootFolder: false + archiveType: zip + archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip + replaceExistingArchive: true + + - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip + displayName: 'Upload package' + artifact: drop + +- stage: Deploy + displayName: 'Deploy Web App' + dependsOn: Build + condition: succeeded() + jobs: + - deployment: DeploymentJob + pool: + name: Default + environment: $(environmentName) + strategy: + runOnce: + deploy: + steps: + + - task: UsePythonVersion@0 + inputs: + versionSpec: '$(pythonVersion)' + displayName: 'Use Python version' + + - task: AzureWebApp@1 + displayName: 'Deploy Azure Web App : pythonwebappmahes' + inputs: + azureSubscription: $(azureServiceConnectionId) + appName: $(webAppName) + package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip \ No newline at end of file diff --git a/taskreport b/taskreport new file mode 100644 index 0000000..4f184d0 --- /dev/null +++ b/taskreport @@ -0,0 +1,32 @@ +import requests +import json +from datetime import datetime, timedelta + +# Puppet master and API token +puppet_master = '' +api_token = '' + +# Calculate the time 24 hours ago in ISO 8601 format +since_time = (datetime.utcnow() - timedelta(hours=24)).strftime('%Y-%m-%dT%H:%M:%SZ') + +# API endpoint +url = f"https://{puppet_master}:8143/orchestrator/v1/jobs?since={since_time}" + +# Headers for the request +headers = { + 'X-Authentication': api_token, + 'Content-Type': 'application/json' +} + +# Make the API request +response = requests.get(url, headers=headers, verify=False) + +# Check if the request was successful +if response.status_code == 200: + jobs = response.json() + # Process the jobs to extract task logs + for job in jobs.get('items', []): + print(f"Job ID: {job['job_id']}, Task: {job['task']}, Status: {job['status']}") + # Add more detailed log extraction if needed +else: + print(f"Failed to fetch jobs: {response.status_code} - {response.text}") diff --git a/taskreport2 b/taskreport2 new file mode 100644 index 0000000..6215005 --- /dev/null +++ b/taskreport2 @@ -0,0 +1,32 @@ +import requests +from datetime import datetime, timedelta + +# Define Puppet master and API token +puppet_master = 'your_puppet_master' +api_token = 'your_api_token' + +# Calculate the time 24 hours ago in ISO 8601 format +since_time = datetime.utcnow() - timedelta(hours=24) + +# Construct the URL +url = f"https://{puppet_master}:8143/orchestrator/v1/jobs" + +# Set the headers for the request +headers = { + 'X-Authentication': api_token, + 'Content-Type': 'application/json' +} + +# Make the API request +response = requests.get(url, headers=headers, verify=False) + +# Check if the request was successful +if response.status_code == 200: + jobs = response.json() + # Filter jobs by the timestamp + filtered_jobs = [job for job in jobs.get('items', []) if datetime.strptime(job['timestamp'], '%Y-%m-%dT%H:%M:%SZ') > since_time] + # Process the filtered jobs + for job in filtered_jobs: + print(f"Job ID: {job['job_id']}, Task: {job['task']}, Status: {job['status']}, Timestamp: {job['timestamp']}") +else: + print(f"Failed to fetch jobs: {response.status_code} - {response.text}") diff --git a/taskreport3 b/taskreport3 new file mode 100644 index 0000000..3f9b206 --- /dev/null +++ b/taskreport3 @@ -0,0 +1,48 @@ +import requests +from datetime import datetime, timedelta + +# Define Puppet master and API token +puppet_master = 'your_puppet_master' +api_token = 'your_api_token' + +# Calculate the time 24 hours ago in ISO 8601 format +since_time = (datetime.utcnow() - timedelta(hours=24)).strftime('%Y-%m-%dT%H:%M:%SZ') + +# Construct the URL +url = f"https://{puppet_master}:8143/orchestrator/v1/jobs" + +# Set the headers for the request +headers = { + 'X-Authentication': api_token, + 'Content-Type': 'application/json' +} + +# Make the API request +response = requests.get(url, headers=headers, verify=False) + +# Check if the request was successful +if response.status_code == 200: + jobs = response.json() + # Debug: Print the entire JSON response to understand its structure + print("Response JSON:", jobs) + + # Filter jobs by the timestamp + filtered_jobs = [ + job for job in jobs.get('items', []) + if datetime.strptime(job['timestamp'], '%Y-%m-%dT%H:%M:%SZ') > datetime.strptime(since_time, '%Y-%m-%dT%H:%M:%SZ') + ] + + # Process the filtered jobs + for job in filtered_jobs: + # Debug: Print each job to understand its structure + print("Job:", job) + + # Adjust keys according to the actual structure + job_id = job.get('job_id', 'N/A') + task = job.get('task', 'N/A') + status = job.get('status', 'N/A') + timestamp = job.get('timestamp', 'N/A') + + print(f"Job ID: {job_id}, Task: {task}, Status: {status}, Timestamp: {timestamp}") +else: + print(f"Failed to fetch jobs: {response.status_code} - {response.text}") diff --git a/templates/about.html b/templates/about.html index 10e2478..3899e26 100644 --- a/templates/about.html +++ b/templates/about.html @@ -4,14 +4,14 @@ - Stanley's Python WebApp + ADO Testing - Simple Python WebApp - Mahes {%extends "templates.html" %} {% block content %}

About

-

Just a sample Web Application made with Python and Flask

+

Just a sample Web Application made with Python and Flask for ADO pipeline

{% endblock %} diff --git a/templates/index.html b/templates/index.html index 6801871..da6635e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -11,7 +11,7 @@ {% block content %}

A Simple Pyton Web App

-

Hello Word!!!!!!!, Our Web App is up and running

+

Simple Web Application made with Python and Flask for ADO pipeline

{% endblock %}