tags:

views:

38

answers:

1

Can this be done in PGSQL? I have a view which I created where hostname,ip, and datacenter are from one table, and ifdesc and if stats from another table. the view output looks like this:

hostname | ip     | datacenter | ifdesc           | ifadminstat | ifoperstat|
---------- ------------------------------------------------------------------
r1        1.1.1.1     dc       GigabitEthernet1/1      2             1
r1        1.1.1.1     dc       GigabitEthernet1/2      2             2
r1        1.1.1.1     dc       GigabitEthernet1/3      2             2
r1        1.1.1.1     dc       GigabitEthernet1/4      2             1
r1        1.1.1.1     dc       GigabitEthernet2/1      2             2
r1        1.1.1.1     dc       GigabitEthernet2/2      2             2
r2        2.2.2.2     dc       GigabitEthernet1/1      2             2
r2        2.2.2.2     dc       GigabitEthernet1/2      2             2

I need to get a count of "ifadminstat = 2" and "ifoperstat = 2" for all interfaces on each blade, for each router (for example... for r1, how many interfaces on blade 1 (GigabitEthernet1/1-48) have "ifadminstat = 2" and "ifoperstat = 2".

I am trying to do the counting in Postgresql then present the results on a website using PHP.

+3  A: 
select hostname, ip, count(1)
  from table
 where ifadminstat = 2 and ifoperstat = 2
 group by hostname, ip
Pablo Santa Cruz
Thank you for the reply. The problem I have is I need the count for every blade in the switch. For each address, and each blade, how many = 2. I believe I will need some sort of regex count(substring(ifdesc, 'Ethernet1/*)
dars