github.com/sacloud/iaas-api-go@v1.12.0/internal/define/simple_monitor.go (about) 1 // Copyright 2022-2023 The sacloud/iaas-api-go Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package define 16 17 import ( 18 "github.com/sacloud/iaas-api-go/internal/define/names" 19 "github.com/sacloud/iaas-api-go/internal/define/ops" 20 "github.com/sacloud/iaas-api-go/internal/dsl" 21 "github.com/sacloud/iaas-api-go/internal/dsl/meta" 22 "github.com/sacloud/iaas-api-go/naked" 23 "github.com/sacloud/iaas-api-go/types" 24 ) 25 26 const ( 27 simpleMonitorAPIName = "SimpleMonitor" 28 simpleMonitorAPIPathName = "commonserviceitem" 29 ) 30 31 var simpleMonitorAPI = &dsl.Resource{ 32 Name: simpleMonitorAPIName, 33 PathName: simpleMonitorAPIPathName, 34 PathSuffix: dsl.CloudAPISuffix, 35 IsGlobal: true, 36 Operations: dsl.Operations{ 37 // find 38 ops.FindCommonServiceItem(simpleMonitorAPIName, simpleMonitorNakedType, findParameter, simpleMonitorView), 39 40 // create 41 ops.CreateCommonServiceItem(simpleMonitorAPIName, simpleMonitorNakedType, simpleMonitorCreateParam, simpleMonitorView), 42 43 // read 44 ops.ReadCommonServiceItem(simpleMonitorAPIName, simpleMonitorNakedType, simpleMonitorView), 45 46 // update 47 ops.UpdateCommonServiceItem(simpleMonitorAPIName, simpleMonitorNakedType, simpleMonitorUpdateParam, simpleMonitorView), 48 // updateSettings 49 ops.UpdateCommonServiceItemSettings(simpleMonitorAPIName, simpleMonitorUpdateSettingsNakedType, simpleMonitorUpdateSettingsParam, simpleMonitorView), 50 51 // delete 52 ops.Delete(simpleMonitorAPIName), 53 54 // momitor 55 ops.MonitorChild(simpleMonitorAPIName, "ResponseTime", "/activity/responsetimesec", 56 monitorParameter, monitors.responseTimeSecModel()), 57 58 // health check 59 ops.HealthStatus(simpleMonitorAPIName, simpleMonitorHealthStatusNakedType, simpleMonitorHealthStatus), 60 }, 61 } 62 63 var ( 64 simpleMonitorNakedType = meta.Static(naked.SimpleMonitor{}) 65 simpleMonitorUpdateSettingsNakedType = meta.Static(naked.SimpleMonitorSettingsUpdate{}) 66 simpleMonitorHealthStatusNakedType = meta.Static(naked.SimpleMonitorHealthCheckStatus{}) 67 68 simpleMonitorView = &dsl.Model{ 69 Name: simpleMonitorAPIName, 70 NakedType: simpleMonitorNakedType, 71 Fields: []*dsl.FieldDesc{ 72 fields.ID(), 73 fields.Name(), 74 fields.Description(), 75 fields.Tags(), 76 fields.Availability(), 77 fields.IconID(), 78 fields.CreatedAt(), 79 fields.ModifiedAt(), 80 fields.Class(), 81 82 // status 83 fields.SimpleMonitorTarget(), 84 85 // settings 86 fields.SimpleMonitorDelayLoop(), 87 fields.SimpleMonitorMaxCheckAttempts(), 88 fields.SimpleMonitorRetryInterval(), 89 fields.SimpleMonitorEnabled(), 90 // settings - health check 91 fields.SimpleMonitorHealthCheck(), 92 // settings - email 93 fields.SimpleMonitorNotifyEmailEnabled(), 94 fields.SimpleMonitorNotifyEmailHTML(), 95 // settings - slack 96 fields.SimpleMonitorNotifySlackEnabled(), 97 fields.SimpleMonitorSlackWebhooksURL(), 98 // settings - notify interval 99 fields.SimpleMonitorNotifyInterval(), 100 // settings - timeout 101 fields.SimpleMonitorTimeout(), 102 // settings hash 103 fields.SettingsHash(), 104 }, 105 } 106 107 simpleMonitorCreateParam = &dsl.Model{ 108 Name: names.CreateParameterName(simpleMonitorAPIName), 109 NakedType: simpleMonitorNakedType, 110 ConstFields: []*dsl.ConstFieldDesc{ 111 { 112 Name: "Class", 113 Type: meta.TypeString, 114 Tags: &dsl.FieldTags{ 115 MapConv: "Provider.Class", 116 }, 117 Value: `"simplemon"`, 118 }, 119 }, 120 Fields: []*dsl.FieldDesc{ 121 // creation time only 122 { 123 Name: "Target", 124 Type: meta.TypeString, 125 Tags: &dsl.FieldTags{ 126 MapConv: "Name/Status.Target", // NameとStatus.Targetに同じ値を設定 127 }, 128 }, 129 130 // settings 131 fields.SimpleMonitorMaxCheckAttempts(), 132 fields.SimpleMonitorRetryInterval(), 133 fields.SimpleMonitorDelayLoop(), 134 fields.SimpleMonitorEnabled(), 135 // settings - health check 136 fields.SimpleMonitorHealthCheck(), 137 138 // settings - email 139 fields.SimpleMonitorNotifyEmailEnabled(), 140 fields.SimpleMonitorNotifyEmailHTML(), 141 142 // settings - slack 143 fields.SimpleMonitorNotifySlackEnabled(), 144 fields.SimpleMonitorSlackWebhooksURL(), 145 fields.SimpleMonitorNotifyInterval(), 146 147 fields.SimpleMonitorTimeout(), 148 149 fields.Description(), 150 fields.Tags(), 151 fields.IconID(), 152 }, 153 } 154 155 simpleMonitorUpdateSettingsParam = &dsl.Model{ 156 Name: names.UpdateSettingsParameterName(simpleMonitorAPIName), 157 NakedType: simpleMonitorNakedType, 158 Fields: []*dsl.FieldDesc{ 159 // settings 160 fields.SimpleMonitorMaxCheckAttempts(), 161 fields.SimpleMonitorRetryInterval(), 162 fields.SimpleMonitorDelayLoop(), 163 fields.SimpleMonitorEnabled(), 164 // settings - health check 165 fields.SimpleMonitorHealthCheck(), 166 // settings - email 167 fields.SimpleMonitorNotifyEmailEnabled(), 168 fields.SimpleMonitorNotifyEmailHTML(), 169 // settings - slack 170 fields.SimpleMonitorNotifySlackEnabled(), 171 fields.SimpleMonitorSlackWebhooksURL(), 172 173 fields.SimpleMonitorNotifyInterval(), 174 175 fields.SimpleMonitorTimeout(), 176 // settings hash 177 fields.SettingsHash(), 178 }, 179 } 180 181 simpleMonitorUpdateParam = &dsl.Model{ 182 Name: names.UpdateParameterName(simpleMonitorAPIName), 183 NakedType: simpleMonitorNakedType, 184 Fields: []*dsl.FieldDesc{ 185 fields.Description(), 186 fields.Tags(), 187 fields.IconID(), 188 189 // settings 190 fields.SimpleMonitorMaxCheckAttempts(), 191 fields.SimpleMonitorRetryInterval(), 192 fields.SimpleMonitorDelayLoop(), 193 fields.SimpleMonitorEnabled(), 194 // settings - health check 195 fields.SimpleMonitorHealthCheck(), 196 // settings - email 197 fields.SimpleMonitorNotifyEmailEnabled(), 198 fields.SimpleMonitorNotifyEmailHTML(), 199 // settings - slack 200 fields.SimpleMonitorNotifySlackEnabled(), 201 fields.SimpleMonitorSlackWebhooksURL(), 202 203 fields.SimpleMonitorNotifyInterval(), 204 205 fields.SimpleMonitorTimeout(), 206 // settings hash 207 fields.SettingsHash(), 208 }, 209 } 210 211 simpleMonitorHealthStatus = &dsl.Model{ 212 Name: "SimpleMonitorHealthStatus", 213 NakedType: simpleMonitorHealthStatusNakedType, 214 Fields: []*dsl.FieldDesc{ 215 fields.Def("LastCheckedAt", meta.TypeTime), 216 fields.Def("LastHealthChangedAt", meta.TypeTime), 217 fields.Def("Health", meta.Static(types.ESimpleMonitorHealth(""))), 218 fields.Def("LatestLogs", meta.TypeStringSlice), 219 }, 220 } 221 )