תצוגה מקדימה: יצירת דוח קיבולת יומי

ניתן להשתמש ב- API Power Platform כדי לחלץ את הפרטים והמטה נתונים השונים שלך מסביבות של Microsoft Power Platform, גם אלה שמשתמשות ב-Microsoft Dataverse וגם אלו שלא. ה- API נמצא בשימוש פנימי על-ידי לקוחות שונים הזמינים כיום, כגון PowerShell.

בערכת לימוד זו, תלמד איך לבצע את הפעולות הבאות:

  • צור Power Automate או קובץ Script של זרימת עבודה של Logic Apps‏ (Azure) או PowerShell שמבצעת אימות עם ה- API של Power Platform.
  • התקשר לנקודת הקצה של סביבות הרשימה כדי לאחזר את פרטי הסביבה של Microsoft Power Platform.
  • חזור דרך אובייקט הקיבולת כדי לאחזר את הצריכה בפועל.
  • שמור את נתוני הצריכה בטבלה לתצוגה.

כדוגמה לתרחיש זה, לקוח מנסה להתמודד עם צריכת הקיבולת שלו כדי שיוכל להבין טוב יותר את חלוקת קיבולת הדיירים הכוללת שלהם לפי מחלקה. זאת על מנת שהלקוח יוכל לבצע כמה פונקציות של חישובי עלויות פנימיים והחזרי תשלום בהתבסס על הכמות שכל מחלקה צורכת מסך הקיבולת הזמינה. לקוח זה משתמש בתיאור הסביבה כדי לקרוא למחלקה שבבעלות כל סביבה.

חשוב

ה-API של Power Platform הוא בתצוגה מקדימה. שם המארח וחוזי הנתונים עשויים להשתנות עד שנקודות הקצה נעשות זמינות. באותה עת, מאמר זה יעודכן עם הפרטים הסופיים של נקודת הקצה.

חיבור והגדרת משנים

להלן פרטים על התחברות ל- Power Platform באופן תיכנותי. באפשרותך לבחור בין חוויית Azure או קבצי Script של PowerShell באמצעות הכרטיסיות למטה.

צור את זרימת העבודה והגדר את המשתנים

כדי להתחיל, נשתמש במדריך זה בזרימת עבודה של Logic Apps. גם זרימת Power Automate מקובלת, וכן כל מנוע תזמור אחר שהחברה שלך מעדיפה להשתמש בו לאוטומציה. כל השיחות לאחזור הנתונים ישתמשו בממשקי API של RESTful כך שכל כלי שתומך ב-REST יעבוד עם מדריך זה.

בקר בפורטל Azure, ואז צור יישום לוגיקה חדש ותן לו שם:

יצירת יישום לוגי.

לאחר סיום ההקצאה, ערוך את זרימת העבודה באמצעות המעצב והגדר מפעיל מופע חוזר שיופעל מדי יום:

הגדר מפעיל מופע חוזר.

לאחר מכן, נצטרך לאתחל חמישה משתנים כמפורט להלן:

  • מזהה SPN - זהו ה-ClientID הראשי של מנהל השירות שלך. הוא ישמש מאוחר יותר לביצוע האימות בהקשר של מנהל השירות. אם אתה משתמש בהקשר של שם משתמש / סיסמה, תוכל לדלג על משתנה זה.
  • DBCapacity - זהו משתנה Float עבור קיבולת מסד הנתונים הנצרכת במגה-בתים.
  • FileCapacity - זהו משתנה Float עבור קיבולת מסד הנתונים הנצרכת במגה-בתים.
  • LogCapacity - זהו משתנה Float עבור קיבולת מסד הנתונים הנצרכת במגה-בתים.
  • SimplifiedEnvironmentArray-Init - זהו משתנה מערך שאנחנו נאכלס בכמה מאפייני סביבה. זה מפשט באופן דרסטי את הפלט הסופי של דוח טבלת HTML.

צור חמישה משתנים.

עתה, נאמת עם Microsoft Azure Active Directory (Azure AD) ונאחזר אסימון להתקשרות לממשק API של Power Platform. אם לא השלמת את התקנת Azure AD שלך, ראה אימות.

במדריך זה, אנחנו משתמשים בכספת מפתח כדי לאחסן את ערך הסוד של מנהל השירות שלנו. באופן זה, מנהל IT יכול להפוך ערך זה לזמין באופן מאובטח עבור זרימת העבודה שלך. לאחר מכן, הוא יאוכלס בשיחת POST אל Azure AD כדי לאחזר את האסימון כפי שמוצג:

אמת עם Azure AD ואחזר אסימון להתקשרות לממשק API של Power Platform.

לאחר מכן ננתח את תגובת אסימון Azure AD לאובייקט מוקלד באמצעות סכימת JSON זו בפעולה 'נתח JSON':

{
    "properties": {
        "access_token": {
            "type": "string"
        },
        "expires_in": {
            "type": "integer"
        },
        "ext_expires_in": {
            "type": "integer"
        },
        "token_type": {
            "type": "string"
        }
    },
    "type": "object"
}

נתח את תגובת האסימון של Azure AD לאובייקט מסוג חזק.

הבאת סביבות

במקטע זה נביא את רשימת הסביבות שאתה מנהל. ניתן לבצע זאת באמצעות API וכן PowerShell.

התקשר לנקודת הקצה של סביבות הרשימה

זה הזמן להתקשר לממשק API של Power Platform. נשתמש בנקודת הקצה של סביבות הרשימה כדי לאחזר את כל הסביבות שלנו ואת המטה נתונים שלהן, ספציפית עם הפרמטר $expand עבור קיבולת. זה גם משתמש בכותרת ההרשאה עם אסימון הנושא שקיבלנו בסעיף הקודם מ-Azure AD. אם השתמשת בהקשר של שם משתמש / סיסמה, תוכל להזין את אסימון הנושא גם בשלב זה.

השתמש בנקודת הקצה של סביבות הרשימה כדי לאחזר את כל הסביבות והמטה נתונים שלהן.

לאחר מכן ננתח את תגובת ה- API של Power Platform לאובייקט מוקלד חזק באמצעות סכימת JSON זו בפעולה 'נתח JSON':

{
    "properties": {
        "value": {
            "items": {
                "properties": {
                    "description": {
                        "type": "string"
                    },
                    "id": {
                        "type": "string"
                    },
                    "location": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string"
                    },
                    "properties": {
                        "properties": {
                            "addons": {
                                "type": "array"
                            },
                            "azureRegion": {
                                "type": "string"
                            },
                            "capacity": {
                                "items": {
                                    "properties": {
                                        "actualConsumption": {
                                            "type": "number"
                                        },
                                        "capacityType": {
                                            "type": "string"
                                        },
                                        "capacityUnit": {
                                            "type": "string"
                                        },
                                        "ratedConsumption": {
                                            "type": "number"
                                        },
                                        "updatedOn": {
                                            "type": "string"
                                        }
                                    },
                                    "required": [
                                        "capacityType",
                                        "actualConsumption",
                                        "ratedConsumption",
                                        "capacityUnit",
                                        "updatedOn"
                                    ],
                                    "type": "object"
                                },
                                "type": "array"
                            },
                            "clientUris": {
                                "properties": {
                                    "admin": {
                                        "type": "string"
                                    },
                                    "maker": {
                                        "type": "string"
                                    }
                                },
                                "type": "object"
                            },
                            "cluster": {
                                "properties": {
                                    "category": {
                                        "type": "string"
                                    },
                                    "number": {
                                        "type": "string"
                                    }
                                },
                                "type": "object"
                            },
                            "connectedGroups": {
                                "type": "array"
                            },
                            "createdBy": {
                                "properties": {
                                    "displayName": {
                                        "type": "string"
                                    },
                                    "id": {
                                        "type": "string"
                                    },
                                    "type": {
                                        "type": "string"
                                    }
                                },
                                "type": "object"
                            },
                            "createdTime": {
                                "type": "string"
                            },
                            "creationType": {
                                "type": "string"
                            },
                            "databaseType": {
                                "type": "string"
                            },
                            "displayName": {
                                "type": "string"
                            },
                            "environmentSku": {
                                "type": "string"
                            },
                            "isDefault": {
                                "type": "boolean"
                            },
                            "linkedEnvironmentMetadata": {
                                "properties": {
                                    "backgroundOperationsState": {
                                        "type": "string"
                                    },
                                    "baseLanguage": {
                                        "type": "number"
                                    },
                                    "createdTime": {
                                        "type": "string"
                                    },
                                    "domainName": {
                                        "type": "string"
                                    },
                                    "friendlyName": {
                                        "type": "string"
                                    },
                                    "instanceApiUrl": {
                                        "type": "string"
                                    },
                                    "instanceState": {
                                        "type": "string"
                                    },
                                    "instanceUrl": {
                                        "type": "string"
                                    },
                                    "platformSku": {
                                        "type": "string"
                                    },
                                    "resourceId": {
                                        "type": "string"
                                    },
                                    "scaleGroup": {
                                        "type": "string"
                                    },
                                    "uniqueName": {
                                        "type": "string"
                                    },
                                    "version": {
                                        "type": "string"
                                    }
                                },
                                "type": "object"
                            },
                            "protectionStatus": {
                                "properties": {
                                    "keyManagedBy": {
                                        "type": "string"
                                    }
                                },
                                "type": "object"
                            },
                            "provisioningState": {
                                "type": "string"
                            },
                            "retentionDetails": {
                                "properties": {
                                    "backupsAvailableFromDateTime": {
                                        "type": "string"
                                    },
                                    "retentionPeriod": {
                                        "type": "string"
                                    }
                                },
                                "type": "object"
                            },
                            "retentionPeriod": {
                                "type": "string"
                            },
                            "runtimeEndpoints": {
                                "properties": {
                                    "microsoft.ApiManagement": {
                                        "type": "string"
                                    },
                                    "microsoft.BusinessAppPlatform": {
                                        "type": "string"
                                    },
                                    "microsoft.CommonDataModel": {
                                        "type": "string"
                                    },
                                    "microsoft.Flow": {
                                        "type": "string"
                                    },
                                    "microsoft.PowerApps": {
                                        "type": "string"
                                    },
                                    "microsoft.PowerAppsAdvisor": {
                                        "type": "string"
                                    }
                                },
                                "type": "object"
                            },
                            "states": {
                                "properties": {
                                    "management": {
                                        "properties": {
                                            "id": {
                                                "type": "string"
                                            }
                                        },
                                        "type": "object"
                                    },
                                    "runtime": {
                                        "properties": {
                                            "id": {
                                                "type": "string"
                                            }
                                        },
                                        "type": "object"
                                    }
                                },
                                "type": "object"
                            },
                            "updateCadence": {
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    }
                                },
                                "type": "object"
                            }
                        },
                        "type": "object"
                    },
                    "type": {
                        "type": "string"
                    }
                },
                "required": [
                    "id",
                    "type",
                    "location",
                    "name",
                    "properties"
                ],
                "type": "object"
            },
            "type": "array"
        }
    },
    "type": "object"
}

נתח את תגובת API של Power Platform לאובייקט מסוג חזק.

חזור באמצעות אובייקט הקיבולת

זהו החלק המורכב ביותר של ההדרכה. כאן נשתמש בלולאה בתוך לולאה כדי לחזור על כל סביבה בתגובת List Environment, ולכל סביבה יש מערך של פרטי קיבולת שנחזור גם עליו. זה יאפשר לנו ללכוד את המידע הדרוש לכל שורת סביבה בטבלת דוחות הקיבולת שלנו.

For-each וניתוח

בואו נעשה את זה, צעד אחר צעד. קודם כל, נשתמש בפקד For Each תוך שימוש ב'ערך' של פלט ה-Parse-List-Response:

השתמש בפקד For Every תוך שימוש ב'ערך' של פלט ה-Parse-List-Response.

עתה, ננתח את הסביבה היחידה הזו לאובייקט מסוג חזק באמצעות סכימת JSON זו:

{
    "properties": {
        "description": {
            "type": "string"
        },
        "id": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "name": {
            "type": "string"
        },
        "properties": {
            "properties": {
                "addons": {
                    "type": "array"
                },
                "azureRegion": {
                    "type": "string"
                },
                "capacity": {
                    "items": {
                        "properties": {
                            "actualConsumption": {
                                "type": "number"
                            },
                            "capacityType": {
                                "type": "string"
                            },
                            "capacityUnit": {
                                "type": "string"
                            },
                            "ratedConsumption": {
                                "type": "number"
                            },
                            "updatedOn": {
                                "type": "string"
                            }
                        },
                        "required": [
                            "capacityType",
                            "actualConsumption",
                            "ratedConsumption",
                            "capacityUnit",
                            "updatedOn"
                        ],
                        "type": "object"
                    },
                    "type": "array"
                },
                "clientUris": {
                    "properties": {
                        "admin": {
                            "type": "string"
                        },
                        "maker": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "cluster": {
                    "properties": {
                        "number": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "connectedGroups": {
                    "type": "array"
                },
                "createdBy": {
                    "properties": {
                        "displayName": {
                            "type": "string"
                        },
                        "id": {
                            "type": "string"
                        },
                        "type": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "createdTime": {
                    "type": "string"
                },
                "creationType": {
                    "type": "string"
                },
                "databaseType": {
                    "type": "string"
                },
                "displayName": {
                    "type": "string"
                },
                "environmentSku": {
                    "type": "string"
                },
                "isDefault": {
                    "type": "boolean"
                },
                "linkedEnvironmentMetadata": {
                    "properties": {
                        "backgroundOperationsState": {
                            "type": "string"
                        },
                        "baseLanguage": {
                            "type": "integer"
                        },
                        "createdTime": {
                            "type": "string"
                        },
                        "domainName": {
                            "type": "string"
                        },
                        "friendlyName": {
                            "type": "string"
                        },
                        "instanceApiUrl": {
                            "type": "string"
                        },
                        "instanceState": {
                            "type": "string"
                        },
                        "instanceUrl": {
                            "type": "string"
                        },
                        "resourceId": {
                            "type": "string"
                        },
                        "scaleGroup": {
                            "type": "string"
                        },
                        "uniqueName": {
                            "type": "string"
                        },
                        "version": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "protectionStatus": {
                    "properties": {
                        "keyManagedBy": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "provisioningState": {
                    "type": "string"
                },
                "retentionDetails": {
                    "properties": {
                        "backupsAvailableFromDateTime": {
                            "type": "string"
                        },
                        "retentionPeriod": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "retentionPeriod": {
                    "type": "string"
                },
                "runtimeEndpoints": {
                    "properties": {
                        "microsoft.ApiManagement": {
                            "type": "string"
                        },
                        "microsoft.BusinessAppPlatform": {
                            "type": "string"
                        },
                        "microsoft.CommonDataModel": {
                            "type": "string"
                        },
                        "microsoft.Flow": {
                            "type": "string"
                        },
                        "microsoft.PowerApps": {
                            "type": "string"
                        },
                        "microsoft.PowerAppsAdvisor": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "states": {
                    "properties": {
                        "management": {
                            "properties": {
                                "id": {
                                    "type": "string"
                                }
                            },
                            "type": "object"
                        },
                        "runtime": {
                            "properties": {
                                "id": {
                                    "type": "string"
                                }
                            },
                            "type": "object"
                        }
                    },
                    "type": "object"
                },
                "updateCadence": {
                    "properties": {
                        "id": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                }
            },
            "type": "object"
        },
        "type": {
            "type": "string"
        }
    },
    "type": "object"
}

אחר כך, נשתמש בפקד For Every אחר, תוך שימוש ב'קיבולת' של פלט Parse-CurrentItem. ועתה, ננתח את זה לאובייקט מסוג חזק באמצעות סכימת JSON זו:

פקד For Each תוך שימוש בקיבולת של פלט Parse-CurrentItem.

כעת אנו יכולים להשתמש בבקרת המתג במאפיין CapacityType מהפלט Parse-Capacity. זה יהיה ערך של 'מסד נתונים', 'קובץ' או 'יומן'. תחת כל מקרה מתג, לכד את המאפיין הקשור 'actualConsumption' אל המשתנה הקשור. במקרה שלמטה תראה שאנחנו לוכדים קיבולת מסד נתונים:

השתמש בבקרת המתג במאפיין CapacityType מהפלט Parse-Capacity.

הצעד האחרון בלולאה 'לכל סביבה' הוא ללכוד את פרטי הסביבה עבור שורה זו בדוח. בעזרת 'צירוף לבקרת משתנה מערך', השתמש בסכמת JSON הבאה:

{
    "properties": {
        "actualConsumption": {
            "type": "number"
        },
        "capacityType": {
            "type": "string"
        },
        "capacityUnit": {
            "type": "string"
        },
        "ratedConsumption": {
            "type": "number"
        },
        "updatedOn": {
            "type": "string"
        }
    },
    "type": "object"
}

לכד את פרטי הסביבה.

בניית טבלת דוחות

מזל טוב, הגעת לחלק הקל! כעת, כאשר יש לנו את מערך קיבולת הסביבה המאוכלס במלואו והפשוט שלנו, אנחנו יכולים להציג אותו בתבנית של טבלה.

השתמש במחבר 'טבלת HTML'

העבר את הערך למחבר 'צור טבלת HTML'.

כשמפעילים את יישום הלוגיקה, אפשר לראות עכשיו את הפלט של דוח טבלת HTML:

פלט של דוח טבלת HTML.

ניתן באופן אופציונלי לשלוח את הדו"ח בדואר אלקטרוני לבעלי העניין בדוגמה זו לצורך חשבונאות עלויות, או לשמור את הנתונים במסד נתונים לצורך ניתוח נוסף ומגמה היסטורית.