Files
doc-exports/docs/config/umn/rms_10_0200.html
Wei, Hongmin 1c932a8714 Config UMN 0816 Version
Reviewed-by: Rumpler, Mihály <mihaly.rumpler@t-systems.com>
Co-authored-by: Wei, Hongmin <weihongmin1@huawei.com>
Co-committed-by: Wei, Hongmin <weihongmin1@huawei.com>
2024-10-01 04:43:48 +00:00

197 lines
18 KiB
HTML

<a name="rms_10_0200"></a><a name="rms_10_0200"></a>
<h1 class="topictitle1">Creating a Custom Query</h1>
<div id="body0000001261824269"><div class="section" id="rms_10_0200__section89381528124515"><h4 class="sectiontitle">Scenarios</h4><p id="rms_10_0200__p95204281541">You can use the query statements preset by Config or customize query statements based on resource configuration attributes to query specific cloud resource configurations.</p>
<p id="rms_10_0200__p159831749371">This section includes the following content:</p>
<ul id="rms_10_0200__ul1388423415915"><li id="rms_10_0200__li988410343915"><a href="#rms_10_0200__section869911416247">Creating a Custom Query</a></li><li id="rms_10_0200__li625354611913"><a href="#rms_10_0200__section118341444172815">Using a Predefined Query</a></li><li id="rms_10_0200__li3847155318913"><a href="#rms_10_0200__section1933391511259">Configuration Examples of Advanced Queries</a></li></ul>
</div>
<div class="section" id="rms_10_0200__section869911416247"><a name="rms_10_0200__section869911416247"></a><a name="section869911416247"></a><h4 class="sectiontitle">Creating a Custom Query</h4><ol id="rms_10_0200__ol123601145252"><li id="rms_10_0200__li133605452510"><span>Log in to the management console.</span></li><li id="rms_10_0200__li17340118202511"><span>Click <span><img id="rms_10_0200__rms_03_0102_rms_03_0102_rms_03_0101_rms_11_3000_rms_03_0102_rms_03_0101_image4857236125711" src="en-us_image_0000001711484518.png"></span> in the upper left corner. Under <strong id="rms_10_0200__rms_03_0102_b17226618104220">Management &amp; Deployment</strong>, click <strong id="rms_10_0200__rms_03_0102_b174231242256">Config</strong>.</span></li><li id="rms_10_0200__li13305181914256"><span>In the navigation pane on the left, choose <strong id="rms_10_0200__b1627512444513">Advanced Queries</strong>.</span></li><li id="rms_10_0200__li192971026102510"><span>Choose the <strong id="rms_10_0200__b113018551718">Custom Queries</strong> tab and click <strong id="rms_10_0200__b78726517212">Create Query</strong> in the upper right corner.</span><p><div class="fignone" id="rms_10_0200__fig12635131572520"><span class="figcap"><b>Figure 1 </b>Create Query</span><br><span><img id="rms_10_0200__image9635215162516" src="en-us_image_0000001924943432.png"></span></div>
</p></li><li id="rms_10_0200__li588482911395"><span>In the <strong id="rms_10_0200__b6529124255115">Query Editor</strong>, enter the query statements.</span><p><p id="rms_10_0200__p18225185213318">On the left of the page, the Schema information is displayed. Schema information shows detailed resource attributes that are specified by the <strong id="rms_10_0200__b892116438011">properties</strong> parameter in the statement. For details about query statements, see <a href="#rms_10_0200__section1933391511259">Configuration Examples of Advanced Queries</a>.</p>
<div class="note" id="rms_10_0200__note04011050144013"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="rms_10_0200__p1040214507404">For supported cloud services and related schemas, see <a href="rms_01_0017.html">Supported Resources</a>.</p>
</div></div>
</p></li><li id="rms_10_0200__li127021620192915"><span>Click <strong id="rms_10_0200__b1454914219225">Save Query</strong> and enter the query name and description.</span><p><p id="rms_10_0200__p387252216398">A query name can contain only digits, letters, underscores (_), and hyphens (-). It cannot exceed 64 characters.</p>
</p></li><li id="rms_10_0200__li16741824112917"><span>Click <strong id="rms_10_0200__b181149474227">OK</strong>.</span><p><div class="fignone" id="rms_10_0200__fig194212555205"><span class="figcap"><b>Figure 2 </b>Saving a query</span><br><span><img id="rms_10_0200__image184221955192018" src="en-us_image_0000001924872408.png"></span></div>
<div class="note" id="rms_10_0200__note19263142314617"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="rms_10_0200__p1544745116592">There is a limit to how many custom queries you can create. If you exceed this limit, you will receive a notification: "The maximum number of custom queries has been reached." Although the query cannot be saved, you can still run the query and export the results.</p>
</div></div>
</p></li><li id="rms_10_0200__li19230157102512"><span>Click <strong id="rms_10_0200__b6535122210261">Run</strong> and then view the query results. Up to 4,000 query results can be displayed and exported.</span></li><li id="rms_10_0200__li9752647154510"><span>Click <strong id="rms_10_0200__b7345410925">Export</strong> and select the format of the file to be exported (CSV or JSON).</span></li></ol>
</div>
<div class="section" id="rms_10_0200__section118341444172815"><a name="rms_10_0200__section118341444172815"></a><a name="section118341444172815"></a><h4 class="sectiontitle">Using a Predefined Query</h4><ol id="rms_10_0200__ol9375338192912"><li id="rms_10_0200__li1470084592914"><span>Choose <strong id="rms_10_0200__b1139616279412">Advanced Queries</strong> &gt; <strong id="rms_10_0200__b124111301845">Default Queries</strong>.</span><p><p id="rms_10_0200__p14515123124919">All default queries are displayed in a list.</p>
</p></li><li id="rms_10_0200__li248710298313"><span>Click <strong id="rms_10_0200__b1360215118493">Query</strong> in the <strong id="rms_10_0200__b19974195444911">Operation</strong> column for the target query.</span><p><p id="rms_10_0200__p1579855418615">Alternatively, click the query name and then click <strong id="rms_10_0200__b166241049125020">Query</strong> in the lower right corner of the query overview page.</p>
<div class="fignone" id="rms_10_0200__fig950312013211"><span class="figcap"><b>Figure 3 </b>Running a default query</span><br><span><img id="rms_10_0200__image1050482018211" src="en-us_image_0000001952151661.png"></span></div>
</p></li><li id="rms_10_0200__li67011455293"><span>In the <strong id="rms_10_0200__b1889412313525">Query Editor</strong>, modify the query.</span><p><p id="rms_10_0200__p070134518293">For details, see <a href="#rms_10_0200__section1933391511259">Configuration Examples of Advanced Queries</a>.</p>
</p></li><li id="rms_10_0200__li12559191012320"><span>Click <strong id="rms_10_0200__b173271846174014">Save As</strong> and enter the query name and description.</span></li><li id="rms_10_0200__li555911100326"><span>In the dialog box that is displayed, click <strong id="rms_10_0200__b183765284522">OK</strong>.</span><p><p id="rms_10_0200__p106114233237">After a new query is created, the new query becomes a custom query and will be displayed in the custom query list.</p>
<div class="fignone" id="rms_10_0200__fig13771358122117"><span class="figcap"><b>Figure 4 </b>Save As</span><br><span><img id="rms_10_0200__image1037885882112" src="en-us_image_0000001925032772.png"></span></div>
</p></li></ol>
</div>
<div class="section" id="rms_10_0200__section1933391511259"><a name="rms_10_0200__section1933391511259"></a><a name="section1933391511259"></a><h4 class="sectiontitle">Configuration Examples of Advanced Queries</h4><p id="rms_10_0200__p12785536194013">Advanced queries use ResourceQL, a subset of SQL SELECT syntax, to query resource configuration data. You do not need to call specific APIs for the query or use multiple APIs to download full data and manually analyze the data. ResourceQL can only query data from the <strong id="rms_10_0200__b2793241440">resources</strong> table.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="rms_10_0200__table1658091413276" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameter descriptions in table <strong id="rms_10_0200__b5832191250">resources</strong></caption><thead align="left"><tr id="rms_10_0200__row165811140279"><th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.4.3.2.4.1.1"><p id="rms_10_0200__p11581101413278">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.4.3.2.4.1.2"><p id="rms_10_0200__p15581191411271">Type</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.4.3.2.4.1.3"><p id="rms_10_0200__p658117146275">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="rms_10_0200__row9581114162713"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p1234102943120">id</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p27321505334">String</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p10375412133515">Specifies the resource ID.</p>
</td>
</tr>
<tr id="rms_10_0200__row15581141482716"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p15341429113110">name</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p97329500335">String</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p19375141215356">Specifies the resource name.</p>
</td>
</tr>
<tr id="rms_10_0200__row758113142273"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p2345291319">provider</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p2732550173319">String</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p12375612103510">Specifies the cloud service name.</p>
</td>
</tr>
<tr id="rms_10_0200__row15581121411271"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p0349291314">type</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p167321450143318">String</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p113751412103511">Specifies the resource type.</p>
</td>
</tr>
<tr id="rms_10_0200__row058101417279"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p034929103112">region_id</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p20732105015335">String</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p1337591233515">Specifies the region ID.</p>
</td>
</tr>
<tr id="rms_10_0200__row458121492713"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p7348291317">project_id</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p1973211509331">String</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p137520127351">Specifies the project ID.</p>
</td>
</tr>
<tr id="rms_10_0200__row458141417278"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p634182914313">ep_id</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p0732350173310">String</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p837511219354">Specifies the enterprise project ID.</p>
</td>
</tr>
<tr id="rms_10_0200__row18981101173214"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p36581948113219">checksum</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p18732155033318">String</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p1937521213512">Specifies the resource checksum.</p>
</td>
</tr>
<tr id="rms_10_0200__row130917123326"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p4658248133219">created</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p873235023317">Date</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p163752012143513">Specifies the time when the resource was created.</p>
</td>
</tr>
<tr id="rms_10_0200__row18861912193217"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p11659184823214">updated</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p373235053310">Date</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p11375512183520">Specifies the time when the resource was updated.</p>
</td>
</tr>
<tr id="rms_10_0200__row2275161313323"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p176594486321">provisioning_state</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p2073212508339">String</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p1637541210357">Specifies the result of an operation on resources.</p>
</td>
</tr>
<tr id="rms_10_0200__row1832912141320"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p146591548153212">tag</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p338282217107">Array(Map&lt;String,String&gt;)</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p537516126351">Specifies the resource tag.</p>
</td>
</tr>
<tr id="rms_10_0200__row193041483219"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.1 "><p id="rms_10_0200__p1465934813214">properties</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.2 "><p id="rms_10_0200__p1573319506330">Map&lt;String,Object&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.3.2.4.1.3 "><p id="rms_10_0200__p837515125358">Specifies the resource attribute details.</p>
</td>
</tr>
</tbody>
</table>
</div>
<p id="rms_10_0200__p14646135915457">Example quires are as follows:</p>
<ul id="rms_10_0200__ul38092174615"><li id="rms_10_0200__li138091919460">Example 1: List ECSs in the <strong id="rms_10_0200__b13597368118">Stopped</strong> state.<pre class="screen" id="rms_10_0200__screen116711434103210">SELECT name
FROM resources
WHERE provider = 'ecs'
AND type = 'cloudservers'
AND properties.status = 'SHUTOFF'</pre>
</li></ul>
<ul id="rms_10_0200__ul665118371503"><li id="rms_10_0200__li13651123712012">Example 2: List EVS disks with certain specifications.<pre class="screen" id="rms_10_0200__screen3974145918321">SELECT *
FROM resources
WHERE provider = 'evs'
AND type = 'volumes'
AND properties.size = 100</pre>
</li><li id="rms_10_0200__li67031145832">Example 3: List OBS buckets queried by fuzzy search.<pre class="screen" id="rms_10_0200__screen13273192073315">SELECT *
FROM resources
WHERE provider = 'obs'
AND type = 'buckets'
AND name LIKE '%figure%'</pre>
</li><li id="rms_10_0200__li820217419510">Example 4: List ECSs and the EVS disks attached to each ECS.<pre class="screen" id="rms_10_0200__screen1330614361337">SELECT ECS_EVS.id AS ecs_id, EVS.id AS evs_id
FROM (
SELECT id, evs_id
FROM (
SELECT id, transform(properties.ExtVolumesAttached, x -&gt; x.id) AS evs_list
FROM resources
WHERE provider = 'ecs'
AND type = 'cloudservers'
) ECS
CROSS JOIN UNNEST(evs_list) AS t (evs_id)
) ECS_EVS, (
SELECT id
FROM resources
WHERE provider = 'evs'
AND type = 'volumes'
) EVS
WHERE ECS_EVS.evs_id = EVS.id</pre>
</li><li id="rms_10_0200__li39113411356">Example 5: List ECSs and the EIPs bound to each ECS.<pre class="screen" id="rms_10_0200__screen17942427183417">SELECT ECS.id AS ECS_id, publicIpAddress AS ip_address
FROM (
SELECT id, transform(properties.addresses, x -&gt; x.addr) AS ip_list
FROM resources
WHERE provider = 'ecs'
AND type = 'cloudservers'
) ECS, (
SELECT name, properties.publicIpAddress
FROM resources
WHERE provider = 'vpc'
AND type = 'publicips'
AND properties.type = 'EIP'
AND properties.status = 'ACTIVE'
) EIP
WHERE CONTAINS (ECS.ip_list, EIP.name)</pre>
</li><li id="rms_10_0200__li145117106619">Example 6: List resources with a quantity greater than 100 in each region.<pre class="screen" id="rms_10_0200__screen19161331143616">WITH counts AS (
SELECT region_id, provider, type, count(*) AS number
FROM resources
GROUP BY region_id, provider, type
)
SELECT *
FROM counts
WHERE number &gt; 100</pre>
<p id="rms_10_0200__p115918281363">For details about query statements, see <a href="rms_06_0700.html">ResourceQL Syntax</a>.</p>
</li></ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rms_10_0000.html">Advanced Queries</a></div>
</div>
</div>