0% found this document useful (0 votes)
76 views6 pages

Import Redfish Import Time From Datetime Import Datetime

This document contains Python code to access temperature metrics from a Redfish API using the redfish Python library. It defines a function called get_temperature_metrics() that takes timestamps as input and returns temperature metrics from the API that match those timestamps. It also includes code to schedule tasks using the schedule library and write API responses to CSV files using Pandas.

Uploaded by

sharma05031989
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views6 pages

Import Redfish Import Time From Datetime Import Datetime

This document contains Python code to access temperature metrics from a Redfish API using the redfish Python library. It defines a function called get_temperature_metrics() that takes timestamps as input and returns temperature metrics from the API that match those timestamps. It also includes code to schedule tasks using the schedule library and write API responses to CSV files using Pandas.

Uploaded by

sharma05031989
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

import redfish

import time

from datetime import datetime


import logging

REDFISH_OBJ.login(auth="session")

response = REDFISH_OBJ.get("/redfish/v1/systems/1", None)

logger = logging.getLogger('redfish')

logger.propagate = False

def get_temperature_metrics(self, timestamps):

"""Get Temperature Metrics from redfish for specific Timestamp

Args:

timestamps (required, dict): Timestamps of different

Temperature metrics from MW

Returns:

temperature_metrics (List): Temperature Metrics from redfish at a

particular Timestamp.

"""

base_url = '/redfish/v1/TelemetryService/MetricReports/'

data = get_redfish_response(self.bmc, base_url +

'autoTemperatureSensorD4D')

metric_values = data.get('MetricValues')
MetricValues = []

temperature_metrics = []

for value in metric_values:

MetricReport = {"metricID": value.get('MetricId'),

"timeStamp": value.get('Timestamp'),

"sourceFQDD": value['Oem']['Dell']['FQDD'],

"value": value.get('MetricValue')}

MetricValues.append(MetricReport)

for sourceFQDD, timestamp in timestamps.items():

for MetricValue in MetricValues:

if MetricValue.get('sourceFQDD') == sourceFQDD and \

MetricValue.get('timeStamp') == timestamp:

temperature_metrics.append(MetricValue)

break

if not temperature_metrics:

print("#########Temperature-MetricValues#########", MetricValues)

print("#########Temperature-timestamps#########", timestamps)

return temperature_metrics

!pip install schedule

import schedule

import time

def func():

print("Geeksforgeeks")
schedule.every(1).seconds.do(func)

while True:

schedule.run_pending()

time.sleep(1)

import pandas as pd

import json

response = """{

"id": 1,

"ageMin": 0,

"ageMax": 100,

"faceConfidence": 66.72220611572266,

"emotion": "ANGRY",

"emotionConfidence": 50.0,

"eyeglasses": false,

"eyeglassesConfidence": 50.38102722167969,

"eyesOpen": true,

"eyesOpenConfidence": 50.20328140258789,

"gender": "Male",

"genderConfidence": 50.462989807128906,

"smile": false,

"smileConfidence": 50.15522384643555,

"sunglasses": false,
"glassesConfidence":50.446510314941406

}"""

file = json.loads(response)

json = pd.DataFrame({"data": file})

json.to_csv("response.csv")

import schedule

import time

import json

import requests

import pandas as pd

def getCSVResponse():

response = requests.get("https://api.covid19api.com/summary").text

response_info = json.loads(response)

responseJson = pd.DataFrame({"data": response_info})

responseJson = responseJson.append(responseJson)

responseJson.to_csv("response1.csv")

print(responseJson)

schedule.every(1).seconds.do(getCSVResponse)

while True:

schedule.run_pending()
time.sleep(1)

You might also like