Skip to content

Commit

Permalink
[IM] Switch to new JSON output for ASN lists in BGPQ3 - closes inex#229
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Aug 22, 2015
1 parent a675853 commit 1a24345
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion application/configs/application.ini.vagrant
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ smokeping.oconf.syslogfacility = "local0"
; Used by nagios-cli.gen-members-conf action to monitor route collector BGP sessions
;router.collector.conf.snmppasswd = 'xxxx'

;irrdb.bgpq.path = '/path/to/bgpq3'
irrdb.bgpq.path = '/usr/local/bin/bgpq3'

; sflow parameters (peer to peer graphs)
sflow.enabled = true
Expand Down
14 changes: 13 additions & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2' | debconf

apt-get install -y apache2 php5 php5-intl php5-mysql php5-rrd php5-cgi php5-cli php5-snmp php5-curl php5-mcrypt \
php5-memcache libapache2-mod-php5 mysql-server mysql-client joe memcached snmp nodejs nodejs-legacy npm \
phpmyadmin
phpmyadmin build-essential

if ! [ -L /var/www ]; then
rm -rf /var/www
Expand Down Expand Up @@ -88,3 +88,15 @@ cp /vagrant/application/configs/application.ini.vagrant /vagrant/application/con
a2enmod rewrite
chmod -R a+rwX /vagrant/storage /vagrant/var
service apache2 restart

# Install BGPQ3
cd /usr/local
wget http://snar.spb.ru/prog/bgpq3/bgpq3-0.1.31.tgz
tar zxf bgpq3-0.1.31.tgz
cd bgpq3-0.1.31/
./configure
make
make install


cd /vagrant
23 changes: 9 additions & 14 deletions library/IXP/BGPQ3.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,19 @@ public function getPrefixList( $asmacro, $proto = 4 )
*/
public function getAsnList( $asmacro, $proto = 4 )
{
$acls = $this->execute( '-3 -l pl -f 999 ' . escapeshellarg( $asmacro ), $proto );
$json = $this->execute( '-3j -l pl -f 999 ' . escapeshellarg( $asmacro ), $proto );
$array = json_decode( $json, true );

// based on the cmd arguments, the acl lines should always start with:
$prelude = "ip as-path access-list pl permit ^999(_[0-9]+)*_(";
$preludeLen = strlen( $prelude );
if( $array === null )
throw new Exception( "Could not decode JSON response from BGPQ when fetching ASN list" );

$asns = [];
foreach( explode( "\n", $acls ) as $acl )
{
if( $acl == 'no ip as-path access-list pl' )
continue;
if( !isset( $array[ 'pl' ] ) )
throw new IXP_Exception( "Named prefix list [pl] expected in decoded JSON but not found when fetching ASN list!" );

$acl = substr( $acl, $preludeLen, -2 ); // also cut off the end
$asns = [];

if ($acl) {
$asns = array_merge( $asns, explode( '|', $acl ) );
}
}
foreach( $array[ 'pl' ] as $asn )
$asns[] = $asn;

return $asns;
}
Expand Down

0 comments on commit 1a24345

Please sign in to comment.