<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title>Mikrotik.moscow [тема: API – проблема с получением списка пулов.]</title>
		<link>http://mikrotik.moscow</link>
		<description>Новое в теме API – проблема с получением списка пулов. форума RouterOS на сайте Mikrotik.moscow [mikrotik.moscow]</description>
		<language>ru</language>
		<docs>http://backend.userland.com/rss2</docs>
		<pubDate>Sun, 16 Aug 2026 20:33:40 -0400</pubDate>
		<item>
			<title>API – проблема с получением списка пулов.</title>
			<description><![CDATA[<b><a href="http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235072">API – проблема с получением списка пулов.</a></b> <i>RouterOS</i> в форуме <a href="http://mikrotik.moscow/forum/forum57/">RouterOS</a>. <br />
			Спасибо за разъяснения! <br />
			<i>08.01.2014 15:43:00, LeoCombes.</i>]]></description>
			<link>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235072</link>
			<guid>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235072</guid>
			<pubDate>Wed, 08 Jan 2014 15:43:00 -0500</pubDate>
			<category>RouterOS</category>
		</item>
		<item>
			<title>API – проблема с получением списка пулов.</title>
			<description><![CDATA[<b><a href="http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235071">API – проблема с получением списка пулов.</a></b> <i>RouterOS</i> в форуме <a href="http://mikrotik.moscow/forum/forum57/">RouterOS</a>. <br />
			Во-первых, спасибо за потраченное время здесь и над разработкой пакета PEAR API, это очень полезно для меня и для других людей. Признателен. Спасибо.<br /><br />В любом случае, мне все еще интересно, почему некоторые команды возвращают !re+!done, а другие только !done. Это точно решение MikroTik (а не мое)... Я могу только предполагать их мотивацию. Обычно это связано с тем, что команда МОЖЕТ вернуть ноль или более одного элемента, но это очевидно не так с "/system/resource/print". Я предполагаю, что это для обратной совместимости: в случае "print" вы явно указываете режим работы, который всегда возвращает единственное значение (поэтому они могут позволить себе перейти от нескольких ответов !re к одному !done), но с ресурсами, возможно, они решат позже изменить то, как это работает, так, чтобы были множественные ответы данных (например, один для каждой "группы", как в Winbox), и некоторая часть того, что мы видим сейчас, останется в первом ответе (например, секция с версией), а ответы, которые мы получаем сейчас, будут совместимы с ответами тогда.<br /><br />Кстати, коллекция не может быть меньше 1, так что вы можете упростить свой код. Кроме того, если вы собираетесь фильтровать по типу, вы можете использовать метод getAllOfType() коллекции, например:<br /><br />```<br />if(count($result) == 1){<br /> &nbsp; &nbsp;$response[$command] = $result-&gt;getAllArguments();<br />}<br />else {<br /> &nbsp; &nbsp;$response[$command] = array();<br /> &nbsp; &nbsp;foreach ($result-&gt;getAllOfType('!re') as $item) {<br /> &nbsp; &nbsp; &nbsp; &nbsp;$response[$command][] = $item-&gt;getAllArguments();<br /> &nbsp; &nbsp;}<br />}<br />```<br /><br />Обратите внимание: как в вашем коде, так и в этом, в случае ошибки будет возвращен пустой массив, что может быть не то, что вам нужно. Если вам нужно проверять наличие ошибок, проверьте $result-&gt;getAllOfType('!trap'). <br />
			<i>07.01.2014 20:58:00, boen_robot.</i>]]></description>
			<link>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235071</link>
			<guid>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235071</guid>
			<pubDate>Tue, 07 Jan 2014 20:58:00 -0500</pubDate>
			<category>RouterOS</category>
		</item>
		<item>
			<title>API – проблема с получением списка пулов.</title>
			<description><![CDATA[<b><a href="http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235070">API – проблема с получением списка пулов.</a></b> <i>RouterOS</i> в форуме <a href="http://mikrotik.moscow/forum/forum57/">RouterOS</a>. <br />
			Итоговое решение, код предлагаю тебе с небольшой модификацией. $result_count = count($result);<br />			if($result_count == 1){<br />				$response[$command] = $result-&gt;getAllArguments();<br />			}<br />			else if($result_count &gt; 1){<br />				foreach ($result as $item) {<br />					if($item-&gt;getType() == "!re"){<br />						$response[$command][] = $item-&gt;getAllArguments();<br />					}<br />				}<br />			} В общем, мне всё ещё интересно, почему некоторые команды возвращают !re+!done, а другие только !done. Спасибо! <br />
			<i>07.01.2014 16:14:00, LeoCombes.</i>]]></description>
			<link>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235070</link>
			<guid>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235070</guid>
			<pubDate>Tue, 07 Jan 2014 16:14:00 -0500</pubDate>
			<category>RouterOS</category>
		</item>
		<item>
			<title>API – проблема с получением списка пулов.</title>
			<description><![CDATA[<b><a href="http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235069">API – проблема с получением списка пулов.</a></b> <i>RouterOS</i> в форуме <a href="http://mikrotik.moscow/forum/forum57/">RouterOS</a>. <br />
			Во-первых, спасибо за ваше время и вклад в разработку пакета PEAR API, это очень полезно для меня и других людей. Хорошая идея, но эта логика не всегда работает. Некоторые команды `count()` возвращают 1 или 2, даже если есть только 1 результат, например: `/system/resource/print`<br />responseTypes = array(<br />	[0] =&gt;'!re'<br />	[1] =&gt;'!done'<br />)<br />count = 2<br /><br />`/ppp/active/print count-only`<br />responseTypes = array(<br />	[0] =&gt;'!done'<br />) <br />count = 1<br /><br />`/ip/pool/used/print count-only`<br />responseTypes = array(<br />	[0] =&gt;'!done'<br />)<br />count = 1<br /><br />`/interface/monitor-traffic interface wan_ether1 once`<br />responseTypes = array(<br />	[0] =&gt;'!re'<br />	[1] =&gt;'!done'<br />)<br />count = 2<br /><br />`/ip/pool/print`<br />responseTypes = array(<br />	[0] =&gt;'!re'<br />	[1] =&gt;'!re'<br />	[2] =&gt;'!re'<br />	[3] =&gt;'!re'<br />	[4] =&gt;'!re'<br />	[5] =&gt;'!done'<br />) <br />count = 6 Почему некоторые команды возвращают !re+!done, а другие только !done? <br />
			<i>07.01.2014 15:12:00, LeoCombes.</i>]]></description>
			<link>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235069</link>
			<guid>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235069</guid>
			<pubDate>Tue, 07 Jan 2014 15:12:00 -0500</pubDate>
			<category>RouterOS</category>
		</item>
		<item>
			<title>API – проблема с получением списка пулов.</title>
			<description><![CDATA[<b><a href="http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235068">API – проблема с получением списка пулов.</a></b> <i>RouterOS</i> в форуме <a href="http://mikrotik.moscow/forum/forum57/">RouterOS</a>. <br />
			Все ответы – это сборник как минимум из одного ответа, поэтому можно безоговорочно перебирать всё. Все примеры, которые ты привёл, содержат ровно один ответ в этом сборнике. Один из них содержит всё необходимое, именно поэтому вызов getAllArguments() работает как и ожидается. Главная причина, по которой итерация не требуется, заключается именно в случаях, подобных этим. Ты можешь проверить количество, вызвав функцию count() над сборником, например: if(count($result) &gt; 1) {<br />//Ты ОБЯЗАН перебирать<br />} else {<br />//Перебирать не обязательно, но ты МОЖЕШЬ, если хочешь<br />} <br />
			<i>07.01.2014 14:01:00, boen_robot.</i>]]></description>
			<link>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235068</link>
			<guid>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235068</guid>
			<pubDate>Tue, 07 Jan 2014 14:01:00 -0500</pubDate>
			<category>RouterOS</category>
		</item>
		<item>
			<title>API – проблема с получением списка пулов.</title>
			<description><![CDATA[<b><a href="http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235067">API – проблема с получением списка пулов.</a></b> <i>RouterOS</i> в форуме <a href="http://mikrotik.moscow/forum/forum57/">RouterOS</a>. <br />
			Спасибо, Boen_robot! Мой код работает отлично без изменений с getAllArguments() в случаях, когда возвращаются только аргументы: /system/resource/print /ppp/active/print count-only /ip/pool/used/print count-only /interface/monitor-traffic interface=ether1 once.<br /><br />Но для случаев команд, которые возвращают коллекцию (например, ‘/ip/pool/print’), мне нужно перебирать ответ. Тогда как я могу заранее узнать, какой тип ответа я получу? Если бы я знал, я бы сделал так (псевдокод):<br /><br />$result = $login['client']-&gt;sendSync($Request);<br />if($result is collection){<br />	// если это коллекция, нужно перебирать<br /> &nbsp; &nbsp; &nbsp;foreach ($result as $item) { &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$response[$commands][] = $item-&gt;getAllArguments();<br /> &nbsp; &nbsp; &nbsp;}<br />}<br />else{<br />	// если не коллекция...<br />	$response[$command] = $result-&gt;getAllArguments();<br />}<br /><br />Как узнать, является ли ответ коллекцией или нет? Возможно ли это? <br />
			<i>07.01.2014 13:48:00, LeoCombes.</i>]]></description>
			<link>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235067</link>
			<guid>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235067</guid>
			<pubDate>Tue, 07 Jan 2014 13:48:00 -0500</pubDate>
			<category>RouterOS</category>
		</item>
		<item>
			<title>API – проблема с получением списка пулов.</title>
			<description><![CDATA[<b><a href="http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235066">API – проблема с получением списка пулов.</a></b> <i>RouterOS</i> в форуме <a href="http://mikrotik.moscow/forum/forum57/">RouterOS</a>. <br />
			Ну вот, как я и думал. $result содержит все ответы, но $result-&gt;getAllArguments(); показывает все аргументы первого ответа, а не все аргументы всех ответов. Чтобы получить все аргументы, нужно перебрать ответы или обратиться к коллекции. Например: $result = $login['client']-&gt;sendSync($Request);<br /> &nbsp; &nbsp; &nbsp;$response[$commands] = array();<br /> &nbsp; &nbsp; &nbsp;foreach ($result as $item) { &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp;$response[$commands][] = $item-&gt;getAllArguments();<br /> &nbsp; &nbsp; &nbsp;} &nbsp;тогда $response[‘/ip/pool/print’] будет числовым массивом, где каждый элемент – это массив всех аргументов для конкретного ответа. Другими словами, $response[‘/ip/pool/print’][0] будет содержать аргументы для первого пула, $response[‘/ip/pool/print’][1] – для второго пула и так далее. <br />
			<i>07.01.2014 13:10:00, boen_robot.</i>]]></description>
			<link>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235066</link>
			<guid>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235066</guid>
			<pubDate>Tue, 07 Jan 2014 13:10:00 -0500</pubDate>
			<category>RouterOS</category>
		</item>
		<item>
			<title>API – проблема с получением списка пулов.</title>
			<description><![CDATA[<b><a href="http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235065">API – проблема с получением списка пулов.</a></b> <i>RouterOS</i> в форуме <a href="http://mikrotik.moscow/forum/forum57/">RouterOS</a>. <br />
			Спасибо, Boen_robot! // $vars содержат все данные для входа<br />$response = test($vars, '/ip/pool/print');<br /><br />function test($nas_access_data, $commands){<br />	$response = array("error" =&gt; 0);<br />	$login = mktk_login($nas_access_data);<br /><br />	if($login['error'] == 0){<br />		$Request = new \PEAR2\Net\RouterOS\Request($commands);				<br />		$result = $login['client']-&gt;sendSync($Request);<br />		$response[$commands] = $result-&gt;getAllArguments();	<br />	}<br />	else $response = $login;<br />	return $response;<br />} <br />
			<i>07.01.2014 12:57:00, LeoCombes.</i>]]></description>
			<link>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235065</link>
			<guid>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235065</guid>
			<pubDate>Tue, 07 Jan 2014 12:57:00 -0500</pubDate>
			<category>RouterOS</category>
		</item>
		<item>
			<title>API – проблема с получением списка пулов.</title>
			<description><![CDATA[<b><a href="http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235064">API – проблема с получением списка пулов.</a></b> <i>RouterOS</i> в форуме <a href="http://mikrotik.moscow/forum/forum57/">RouterOS</a>. <br />
			Как выглядит твой PHP-код? Подозреваю, что ты используешь возможность напрямую читать первый ответ, вместо того чтобы перебирать все ответы. <br />
			<i>07.01.2014 11:10:00, boen_robot.</i>]]></description>
			<link>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235064</link>
			<guid>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235064</guid>
			<pubDate>Tue, 07 Jan 2014 11:10:00 -0500</pubDate>
			<category>RouterOS</category>
		</item>
		<item>
			<title>API – проблема с получением списка пулов.</title>
			<description><![CDATA[<b><a href="http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235063">API – проблема с получением списка пулов.</a></b> <i>RouterOS</i> в форуме <a href="http://mikrotik.moscow/forum/forum57/">RouterOS</a>. <br />
			Привет! Пытаюсь получить IP-пулы через API. Когда пытаюсь из терминала, получаю: [admin@mktk] &gt; ip pool print<br /># NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RANGES &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />0 pool_red_slave &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 192.168.3.100-192.168.3.200<br />1 pool_red_slave2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;192.168.4.100-192.168.4.200<br />2 pool_privadas &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;172.16.1.2-172.16.1.254 &nbsp; &nbsp; &nbsp; &nbsp;<br />3 pool_prueba &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10.10.10.100-10.10.10.200 &nbsp; &nbsp; &nbsp;<br />4 pool_DVR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 192.168.2.100-192.168.2.200<br /><br />Когда пытаюсь с PHP командой ‘/ip/pool/print’ через PEAR2_Net_RouterOS, получаю только первый результат: .id “*1” name	“pool_red_slave” next-pool “pool_red_slave2” ranges “192.168.3.100-192.168.3.200”<br /><br />Routerboard - RB1100Hx2 v5.20<br /><br />У кого-нибудь такое же поведение? <br />
			<i>06.01.2014 22:49:00, LeoCombes.</i>]]></description>
			<link>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235063</link>
			<guid>http://mikrotik.moscow/forum/forum57/61478-api-_-problema-s-polucheniem-spiska-pulov./message235063</guid>
			<pubDate>Mon, 06 Jan 2014 22:49:00 -0500</pubDate>
			<category>RouterOS</category>
		</item>
	</channel>
</rss>
