package com.bocloud.cmp.entity.enums.azure;

/**
 * @Company: 博云 www.bocloud.com
 * @ClassName: Templates
 * @Description:
 * @author: zhenpingLi/李振平
 * @date: 2020/8/14 9:18
 */
public enum AutomationTemplates {

    AUTOMATIONACCOUNT("{\"properties\":{\"mode\":\"Incremental\",\"template\":{\"$schema\":\"https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#\",\"contentVersion\":\"1.0.0.0\",\"parameters\":{\"workspaceName\":{\"type\":\"string\",\"defaultValue\":\"logAnalytic\",\"metadata\":{\"description\":\"Workspace name\"}},\"sku\":{\"type\":\"string\",\"allowedValues\":[\"pergb2018\",\"Free\",\"Standalone\",\"PerNode\",\"Standard\",\"Premium\"],\"defaultValue\":\"pergb2018\",\"metadata\":{\"description\":\"Pricing tier: perGB2018 or legacy tiers (Free, Standalone, PerNode, Standard or Premium) which are not available to all customers.\"}},\"dataRetention\":{\"type\":\"int\",\"defaultValue\":30,\"minValue\":7,\"maxValue\":730,\"metadata\":{\"description\":\"Number of days of retention. Workspaces in the legacy Free pricing tier can only have 7 days.\"}},\"location\":{\"type\":\"string\",\"defaultValue\":\"[resourceGroup().location]\",\"metadata\":{\"description\":\"Location for all resources.\"}},\"automationAccountName\":{\"type\":\"string\",\"defaultValue\":\"automationAccout\",\"metadata\":{\"description\":\"Automation account name\"}},\"automationAccountLocation\":{\"type\":\"string\",\"defaultValue\":\"[resourceGroup().location]\",\"metadata\":{\"description\":\"Specify the location in which to create the Automation account.\"}}},\"variables\":{\"Updates\":{\"name\":\"[concat('Updates', '(', parameters('workspaceName'), ')')]\",\"galleryName\":\"Updates\"}},\"resources\":[{\"type\":\"Microsoft.OperationalInsights/workspaces\",\"name\":\"[parameters('workspaceName')]\",\"apiVersion\":\"2020-03-01-preview\",\"location\":\"[parameters('location')]\",\"properties\":{\"sku\":{\"name\":\"[parameters('sku')]\"},\"retentionInDays\":\"[parameters('dataRetention')]\",\"features\":{\"searchVersion\":1,\"legacy\":0,\"enableLogAccessUsingOnlyResourcePermissions\":true}},\"resources\":[{\"apiVersion\":\"2015-11-01-preview\",\"location\":\"[parameters('location')]\",\"name\":\"[variables('Updates').name]\",\"type\":\"Microsoft.OperationsManagement/solutions\",\"id\":\"[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.OperationsManagement/solutions/', variables('Updates').name)]\",\"dependsOn\":[\"[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]\"],\"properties\":{\"workspaceResourceId\":\"[resourceId('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]\"},\"plan\":{\"name\":\"[variables('Updates').name]\",\"publisher\":\"Microsoft\",\"promotionCode\":\"\",\"product\":\"[concat('OMSGallery/', variables('Updates').galleryName)]\"}}]},{\"type\":\"Microsoft.Automation/automationAccounts\",\"apiVersion\":\"2018-06-30\",\"name\":\"[parameters('automationAccountName')]\",\"location\":\"[parameters('automationAccountLocation')]\",\"dependsOn\":[],\"tags\":{},\"properties\":{\"sku\":{\"name\":\"Basic\"}}},{\"apiVersion\":\"2020-03-01-preview\",\"type\":\"Microsoft.OperationalInsights/workspaces/linkedServices\",\"name\":\"[concat(parameters('workspaceName'), '/' , 'Automation')]\",\"location\":\"[parameters('location')]\",\"dependsOn\":[\"[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]\",\"[concat('Microsoft.Automation/automationAccounts/', parameters('automationAccountName'))]\"],\"properties\":{\"resourceId\":\"[resourceId('Microsoft.Automation/automationAccounts/', parameters('automationAccountName'))]\"}}]},\"parameters\":{\"location\":{\"value\":\"chinaeast2\"}}}}"),

    //查询计算机
    COMPUTER("{\"top\":1000000000,\"query\":\"let _rows = Heartbeat\\n| where TimeGenerated>ago(12h) and OSType==\\\"Linux\\\" and notempty(Computer)\\n| summarize arg_max(TimeGenerated, Solutions, Computer, ResourceId, ComputerEnvironment, VMUUID) by SourceComputerId\\n| where Solutions has \\\"updates\\\" \\n| extend vmuuId=VMUUID, azureResourceId=ResourceId, osType=1,\\nenvironment=iff(ComputerEnvironment=~\\\"Azure\\\", 1, 2),\\nscopedToUpdatesSolution=true, lastUpdateAgentSeenTime=\\\"\\\"\\n| join kind=leftouter (Update\\n| where TimeGenerated>ago(5h) and OSType==\\\"Linux\\\" and SourceComputerId in ((Heartbeat\\n| where TimeGenerated>ago(12h) and OSType==\\\"Linux\\\" and notempty(Computer)\\n| summarize arg_max(TimeGenerated, Solutions) by SourceComputerId\\n| where Solutions has \\\"updates\\\" | distinct SourceComputerId))\\n| summarize hint.strategy=partitioned arg_max(TimeGenerated, UpdateState, Classification, Product, Computer, ComputerEnvironment) by SourceComputerId, Product, ProductArch \\n| summarize Computer=any(Computer), ComputerEnvironment=any(ComputerEnvironment), missingCriticalUpdatesCount=countif(Classification has \\\"Critical\\\" and UpdateState=~\\\"Needed\\\"),\\nmissingSecurityUpdatesCount=countif(Classification has \\\"Security\\\" and UpdateState=~\\\"Needed\\\"),\\nmissingOtherUpdatesCount=countif(Classification !has \\\"Critical\\\" and Classification !has \\\"Security\\\" and UpdateState=~\\\"Needed\\\"),\\nlastAssessedTime=max(TimeGenerated), lastUpdateAgentSeenTime=\\\"\\\" by SourceComputerId\\n| extend compliance=iff(missingCriticalUpdatesCount > 0 or missingSecurityUpdatesCount > 0, 2, 1)\\n| extend ComplianceOrder=iff(missingCriticalUpdatesCount > 0 or missingSecurityUpdatesCount > 0 or missingOtherUpdatesCount > 0, 1, 3)) on SourceComputerId\\n| project id=SourceComputerId, displayName=Computer, sourceComputerId=SourceComputerId, azureResourceId, scopedToUpdatesSolution=true,\\nmissingCriticalUpdatesCount=coalesce(missingCriticalUpdatesCount, -1), missingSecurityUpdatesCount=coalesce(missingSecurityUpdatesCount, -1), missingOtherUpdatesCount=coalesce(missingOtherUpdatesCount, -1), compliance=coalesce(compliance, 4), lastAssessedTime, lastUpdateAgentSeenTime, osType=1, environment=iff(ComputerEnvironment=~\\\"Azure\\\", 1, 2), ComplianceOrder=coalesce(ComplianceOrder, 2)\\n | union(Heartbeat\\n| where TimeGenerated>ago(12h) and OSType=~\\\"Windows\\\" and notempty(Computer)\\n| summarize arg_max(TimeGenerated, Solutions, Computer, ResourceId, ComputerEnvironment, VMUUID) by SourceComputerId\\n| where Solutions has \\\"updates\\\" \\n| extend vmuuId=VMUUID, azureResourceId=ResourceId, osType=2,\\nenvironment=iff(ComputerEnvironment=~\\\"Azure\\\", 1, 2),\\nscopedToUpdatesSolution=true, lastUpdateAgentSeenTime=\\\"\\\"\\n| join kind=leftouter (Update\\n| where TimeGenerated>ago(14h) and OSType!=\\\"Linux\\\" and SourceComputerId in ((Heartbeat\\n| where TimeGenerated>ago(12h) and OSType=~\\\"Windows\\\" and notempty(Computer)\\n| summarize arg_max(TimeGenerated, Solutions) by SourceComputerId\\n| where Solutions has \\\"updates\\\" | distinct SourceComputerId))\\n| summarize hint.strategy=partitioned arg_max(TimeGenerated, UpdateState, Classification, Title, Optional, Approved, Computer, ComputerEnvironment) by Computer, SourceComputerId, UpdateID \\n| summarize Computer=any(Computer), ComputerEnvironment=any(ComputerEnvironment), missingCriticalUpdatesCount=countif(Classification has \\\"Critical\\\" and UpdateState=~\\\"Needed\\\" and Approved!=false),\\nmissingSecurityUpdatesCount=countif(Classification has \\\"Security\\\" and UpdateState=~\\\"Needed\\\" and Approved!=false),\\nmissingOtherUpdatesCount=countif(Classification !has \\\"Critical\\\" and Classification !has \\\"Security\\\" and UpdateState=~\\\"Needed\\\" and Optional==false and Approved!=false),\\nlastAssessedTime=max(TimeGenerated), lastUpdateAgentSeenTime=\\\"\\\" by SourceComputerId\\n| extend compliance=iff(missingCriticalUpdatesCount > 0 or missingSecurityUpdatesCount > 0, 2, 1)\\n| extend ComplianceOrder=iff(missingCriticalUpdatesCount > 0 or missingSecurityUpdatesCount > 0 or missingOtherUpdatesCount > 0, 1, 3)) on SourceComputerId\\n| project id=SourceComputerId, displayName=Computer, sourceComputerId=SourceComputerId, azureResourceId, scopedToUpdatesSolution=true,\\nmissingCriticalUpdatesCount=coalesce(missingCriticalUpdatesCount, -1), missingSecurityUpdatesCount=coalesce(missingSecurityUpdatesCount, -1), missingOtherUpdatesCount=coalesce(missingOtherUpdatesCount, -1), compliance=coalesce(compliance, 4), lastAssessedTime, lastUpdateAgentSeenTime, osType=2, environment=iff(ComputerEnvironment=~\\\"Azure\\\", 1, 2), ComplianceOrder=coalesce(ComplianceOrder, 2)\\n) | order by ComplianceOrder asc, missingCriticalUpdatesCount desc, missingSecurityUpdatesCount desc, missingOtherUpdatesCount desc, displayName asc | project-away ComplianceOrder;\\n_rows | summarize _count=count()\\n| union (_rows | take 10000)\\n| sort by _count desc nulls last\",\"workspaces\":[],\"authorizedResources\":[]}"),

    //查询补丁
    MISSINGUPDATE2("{\"top\":1000000000,\"query\":\"let _rows = Update\\n| where TimeGenerated>ago(5h) and OSType==\\\"Linux\\\" and SourceComputerId in ((Heartbeat\\n| where TimeGenerated>ago(12h) and OSType==\\\"Linux\\\" and notempty(Computer)\\n| summarize arg_max(TimeGenerated, Solutions) by SourceComputerId\\n| where Solutions has \\\"updates\\\" | distinct SourceComputerId))\\n| summarize hint.strategy=partitioned arg_max(TimeGenerated, UpdateState, Classification, BulletinUrl, BulletinID) by SourceComputerId, Product, ProductArch | where UpdateState=~\\\"Needed\\\"  | project-away UpdateState, TimeGenerated\\n| summarize computersCount=dcount(SourceComputerId, 2), ClassificationWeight=max(iff(Classification has \\\"Critical\\\", 4, iff(Classification has \\\"Security\\\", 2, 1)))\\nby id=strcat(Product, \\\"_\\\", ProductArch), displayName=Product, productArch=ProductArch, classification=Classification, InformationId=BulletinID, InformationUrl=tostring(split(BulletinUrl, \\\";\\\", 0)[0]), osType=1 | union(Update\\n| where TimeGenerated>ago(14h) and OSType!=\\\"Linux\\\" and (Optional==false or Classification has \\\"Critical\\\" or Classification has \\\"Security\\\") and SourceComputerId in ((Heartbeat\\n| where TimeGenerated>ago(12h) and OSType=~\\\"Windows\\\" and notempty(Computer)\\n| summarize arg_max(TimeGenerated, Solutions) by SourceComputerId\\n| where Solutions has \\\"updates\\\" | distinct SourceComputerId))\\n| summarize hint.strategy=partitioned arg_max(TimeGenerated, UpdateState, Classification, Title, KBID, PublishedDate, Approved) by Computer, SourceComputerId, UpdateID\\n| where UpdateState=~\\\"Needed\\\" and Approved!=false  | project-away UpdateState, Approved, TimeGenerated\\n| summarize computersCount=dcount(SourceComputerId, 2), displayName=any(Title), publishedDate=min(PublishedDate), ClassificationWeight=max(iff(Classification has \\\"Critical\\\", 4, iff(Classification has \\\"Security\\\", 2, 1)))\\nby id=strcat(UpdateID, \\\"_\\\", KBID), classification=Classification, InformationId=strcat(\\\"KB\\\", KBID), InformationUrl=iff(isnotempty(KBID), strcat(\\\"https://support.microsoft.com/kb/\\\", KBID), \\\"\\\"), osType=2) | sort by ClassificationWeight desc, computersCount desc, displayName asc\\n| extend informationLink=(iff(isnotempty(InformationId) and isnotempty(InformationUrl), toobject(strcat('{ \\\"uri\\\": \\\"', InformationUrl, '\\\", \\\"text\\\": \\\"', InformationId, '\\\", \\\"target\\\": \\\"blank\\\" }')), toobject('')))\\n| project-away ClassificationWeight, InformationId, InformationUrl;\\n_rows | summarize _count=count()\\n| union (_rows | take 10000)\\n| sort by _count desc nulls last\",\"workspaces\":[],\"authorizedResources\":[]}"),

    //查询历史记录详情里的跨计算机更新
    DEPLOYEDUPDATESSUMMARY2("{\"top\":1000000000,\"query\":\"UpdateRunProgress\\n| where OSType==\\\"Linux\\\" and CorrelationId==\\\"38ca5139-574f-43a5-b21b-e73dee22a8f4\\\"\\n| summarize arg_max(TimeGenerated, InstallationStatus) by SourceComputerId, Product\\n| summarize RollupStatus=max(case(InstallationStatus contains \\\"Failed\\\",3, InstallationStatus contains \\\"Succeeded\\\", 0, InstallationStatus=~\\\"NotIncluded\\\" or InstallationStatus=~\\\"Excluded\\\", 1, 2)) by Product\\n| summarize Count=count() by RollupStatus\\n| summarize totalCount=sum(Count),\\nfailedCount=sumif(Count, RollupStatus==3),\\nsucceededCount=sumif(Count, RollupStatus==0),\\nnotAttemptedCount=sumif(Count, RollupStatus==2),\\nnotSelectedCount=sumif(Count, RollupStatus==1)\",\"workspaces\":[],\"authorizedResources\":[],\"timespan\":\"2020-08-17T05:53:39.746Z/2020-08-17T12:48:39.746Z\"}"),

    //查询历史记录详情里的补丁更新情况
    DEPLOYEDUPDATEINMULTIMACHINEVIEW("{\"top\":1000000000,\"query\":\"let _rows = UpdateRunProgress\\n| where OSType==\\\"Linux\\\" and CorrelationId==\\\"38ca5139-574f-43a5-b21b-e73dee22a8f4\\\"\\n| summarize arg_max(TimeGenerated, InstallationStatus) by SourceComputerId, Title\\n| summarize totalCount=dcount(SourceComputerId, 2), displayName=any(Title),\\nfailedCount=dcountif(SourceComputerId, InstallationStatus contains \\\"Failed\\\", 2),\\nnotAttemptedCount=dcountif(SourceComputerId, InstallationStatus=~\\\"NotStarted\\\", 2),\\nnotSelectedCount=dcountif(SourceComputerId, InstallationStatus=~\\\"NotIncluded\\\" or InstallationStatus=~\\\"Excluded\\\", 2) by id=Title | order by failedCount desc, notAttemptedCount desc, notSelectedCount desc, displayName asc\\n| project id, displayName, ['statistics']=toobject(strcat('{ \\\"notAttemptedCount\\\": ', notAttemptedCount, ', \\\"notSelectedCount\\\": ', notSelectedCount, ', \\\"failedCount\\\": ', failedCount, ', \\\"totalCount\\\": ', totalCount, '}'));\\n_rows | summarize _count=count()\\n| union (_rows | take 10000)\\n| sort by _count desc nulls last\",\"workspaces\":[],\"authorizedResources\":[],\"timespan\":\"2020-08-17T05:53:39.746Z/2020-08-17T12:48:39.746Z\"}");
    AutomationTemplates(String value) {
        this.value = value;
    }

    private String value;

    public String getValue() {
        return value;
    }
}