Thread: [OpenVMPS-devel] External program: answer not being accepted
Brought to you by:
dori_seliskar
From: Sean B. <se...@bo...> - 2005-11-04 15:27:35
|
Hi, I've having problems getting a basic external plug-in to work. I have a simple PHP script: while (true) { $fd = fopen("php://stdin", "r"); $line=rtrim( fgets($fd, 1024) ); if (strlen($line) > 0) { list($domain, $switch, $port, $lastvlan, $mac)=explode(" ", $line); echo("ALLOW $lastvlan\n"); flush(); // don't know if this needed, but doesn't seem to matter } fclose($fd); sleep(1); # wait 1 secs, before retrying } The data arrives OK, but what I send back never seems to be sent by vmpsd, I've tried echo("ALLOW $lastvlan\n\n"); echo("ALLOW $lastvlan\n"); echo("ALLOW $lastvlan"); but no luck. IN vmpsd's external.c is seems to happen around here: write(tocli[1], str, strlen(str)); n = readline(fromcli[0], buf, 255); The first line seems to work fine, the second never comes back. I added in vmps_log(VQP|DEBUG, ">>>> Sending: %s ", str); before the "write" line and this works. When I look at the code for readline() it seems to read char by char until it hits 255 or \n. So it should work. In syslog I see: Nov 3 23:04:37 INOCESvmps1 vmpsd: ================================== Nov 3 23:04:37 INOCESvmps1 vmpsd: VQP Request Nov 3 23:04:37 INOCESvmps1 vmpsd: Unknown: 1 Nov 3 23:04:37 INOCESvmps1 vmpsd: Request Type: 1 Nov 3 23:04:37 INOCESvmps1 vmpsd: Response: 0 Nov 3 23:04:37 INOCESvmps1 vmpsd: No. Data Items: 6 Nov 3 23:04:37 INOCESvmps1 vmpsd: Sequence No.: 4660 Nov 3 23:04:37 INOCESvmps1 vmpsd: Client IP address: 193.111.222.1 Nov 3 23:04:37 INOCESvmps1 vmpsd: Port name: Fa0/17 Nov 3 23:04:37 INOCESvmps1 vmpsd: Vlan name: test Nov 3 23:04:37 INOCESvmps1 vmpsd: Domain name: Domain Nov 3 23:04:37 INOCESvmps1 vmpsd: MAC address: 080020b0cb95 Nov 3 23:04:37 INOCESvmps1 vmpsd: >>>> Sending: Domain 193.111.222.1 Fa0/17 switch1 0800.20b0.cb95 My external sends back: "ALLOW test", but vmpsd never sees it arriving and vmpsd just sits there waiting. Any sugsestions /tips? Thanks, Sean |
From: David S. <dav...@me...> - 2005-11-22 12:39:33
|
What I have is based differently. Can you try changing your application? $fd = fopen("php://stdin", "r"); while (true) { $line=rtrim( fgets($fd, 1024) ); if (strlen($line) > 0) { list($domain, $switch, $port, $lastvlan, $mac)=explode(" ", $line); echo("ALLOW $lastvlan\n"); flush(); // don't know if this needed, but doesn't seem to matter } } fclose($fd); The program will block on the read string until it gets passed something. The external application starts at the same time as vmpsd, or at least the first time it's used. The flush is required, maybe needing to specify stdout?? Dave System Administrator m/v Africa Mercy Mercy Ships tel: 0191 483 8413 ex 108 fax: 0870 460 0764 > -----Original Message----- > From: vmp...@li... > [mailto:vmp...@li...] On Behalf Of > Sean Boran > Sent: 04 November 2005 15:27 > To: vmp...@li... > Subject: [OpenVMPS-devel] External program: answer not being accepted > > > Hi, > > I've having problems getting a basic external plug-in to work. > > I have a simple PHP script: > > while (true) { > $fd = fopen("php://stdin", "r"); > > $line=rtrim( fgets($fd, 1024) ); > if (strlen($line) > 0) { > list($domain, $switch, $port, $lastvlan, > $mac)=explode(" ", $line); > echo("ALLOW $lastvlan\n"); > flush(); // don't know if this needed, but doesn't > seem to matter > } > fclose($fd); > sleep(1); # wait 1 secs, before retrying > } > > The data arrives OK, but what I send back never seems to be > sent by vmpsd, > I've tried > echo("ALLOW $lastvlan\n\n"); > echo("ALLOW $lastvlan\n"); > echo("ALLOW $lastvlan"); > > but no luck. > > IN vmpsd's external.c is seems to happen around here: > write(tocli[1], str, strlen(str)); > n = readline(fromcli[0], buf, 255); > The first line seems to work fine, the second never comes back. > I added in > vmps_log(VQP|DEBUG, ">>>> Sending: %s ", str); > before the "write" line and this works. > > When I look at the code for readline() it seems to read char > by char until > it hits 255 or \n. So it should work. > > In syslog I see: > > Nov 3 23:04:37 INOCESvmps1 vmpsd: ================================== > Nov 3 23:04:37 INOCESvmps1 vmpsd: VQP Request > Nov 3 23:04:37 INOCESvmps1 vmpsd: Unknown: 1 > Nov 3 23:04:37 INOCESvmps1 vmpsd: Request Type: 1 > Nov 3 23:04:37 INOCESvmps1 vmpsd: Response: 0 > Nov 3 23:04:37 INOCESvmps1 vmpsd: No. Data Items: 6 > Nov 3 23:04:37 INOCESvmps1 vmpsd: Sequence No.: 4660 > Nov 3 23:04:37 INOCESvmps1 vmpsd: Client IP address: 193.111.222.1 > Nov 3 23:04:37 INOCESvmps1 vmpsd: Port name: Fa0/17 > Nov 3 23:04:37 INOCESvmps1 vmpsd: Vlan name: test > Nov 3 23:04:37 INOCESvmps1 vmpsd: Domain name: Domain > Nov 3 23:04:37 INOCESvmps1 vmpsd: MAC address: 080020b0cb95 > Nov 3 23:04:37 INOCESvmps1 vmpsd: >>>> Sending: Domain > 193.111.222.1 Fa0/17 > switch1 0800.20b0.cb95 > > My external sends back: "ALLOW test", but vmpsd never sees it > arriving and > vmpsd just sits there waiting. > > Any sugsestions /tips? > > Thanks, > > Sean > > > > > ------------------------------------------------------- > SF.Net email is sponsored by: > Tame your development challenges with Apache's Geronimo App > Server. Download > it for free - -and be entered to win a 42" plasma tv or your very own > Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php > _______________________________________________ > Vmps-devel mailing list > Vmp...@li... > https://lists.sourceforge.net/lists/listinfo/vmps-devel > |
From: Sean B. <se...@bo...> - 2005-11-22 14:36:00
|
Hi, I'd should have posted a followup... in fact I was not separating stdin/out properly. Its working fine and looks like below. In fact its now quite intelligent and detects hubs (assigning a vlan based on a lookupto see what vlan is already active on a port), and allows a default vlan to be set per port (if needed). I can share code if its of interest, but its very specific to my setup/DB here.. Sean logit("Connect to DB" ); db_connect(); while (true) { $in = fopen("php://stdin", "r"); $out = fopen("php://stdout", "w"); if ($out and $in) { $line=rtrim( fgets($in, 1024) ); if (strlen($line) > 0) { list($domain, $switch, $port, $lastvlan, $mac)=explode(" ", $line); // The meat come here, decisional logic } fclose($in); fclose($out); #sleep(1); # wait 1 secs, before retrying } logit("Log /DB close, reconnect"); mysql_close($connect); ?> > -----Original Message----- > From: vmp...@li... > [mailto:vmp...@li...] On Behalf Of > David Smith > Sent: mardi, 22. novembre 2005 13:39 > To: vmp...@li... > Subject: RE: [OpenVMPS-devel] External program: answer not > being accepted > > What I have is based differently. Can you try changing your > application? > > $fd = fopen("php://stdin", "r"); > while (true) { > $line=rtrim( fgets($fd, 1024) ); > if (strlen($line) > 0) { > list($domain, $switch, $port, $lastvlan, > $mac)=explode(" ", $line); > echo("ALLOW $lastvlan\n"); > flush(); // don't know if this needed, but doesn't > seem to matter > } > } > fclose($fd); > > > The program will block on the read string until it gets > passed something. > > The external application starts at the same time as vmpsd, or > at least the > first time it's used. > > The flush is required, maybe needing to specify stdout?? > > Dave > System Administrator > m/v Africa Mercy > Mercy Ships > tel: 0191 483 8413 ex 108 > fax: 0870 460 0764 > > > > -----Original Message----- > > From: vmp...@li... > > [mailto:vmp...@li...] On Behalf Of > > Sean Boran > > Sent: 04 November 2005 15:27 > > To: vmp...@li... > > Subject: [OpenVMPS-devel] External program: answer not > being accepted > > > > > > Hi, > > > > I've having problems getting a basic external plug-in to work. > > > > I have a simple PHP script: > > > > while (true) { > > $fd = fopen("php://stdin", "r"); > > > > $line=rtrim( fgets($fd, 1024) ); > > if (strlen($line) > 0) { > > list($domain, $switch, $port, $lastvlan, > > $mac)=explode(" ", $line); > > echo("ALLOW $lastvlan\n"); > > flush(); // don't know if this needed, but doesn't > > seem to matter > > } > > fclose($fd); > > sleep(1); # wait 1 secs, before retrying > > } > > > > The data arrives OK, but what I send back never seems to be > > sent by vmpsd, > > I've tried > > echo("ALLOW $lastvlan\n\n"); > > echo("ALLOW $lastvlan\n"); > > echo("ALLOW $lastvlan"); > > > > but no luck. > > > > IN vmpsd's external.c is seems to happen around here: > > write(tocli[1], str, strlen(str)); > > n = readline(fromcli[0], buf, 255); > > The first line seems to work fine, the second never comes back. > > I added in > > vmps_log(VQP|DEBUG, ">>>> Sending: %s ", str); > > before the "write" line and this works. > > > > When I look at the code for readline() it seems to read char > > by char until > > it hits 255 or \n. So it should work. > > > > In syslog I see: > > > > Nov 3 23:04:37 INOCESvmps1 vmpsd: > ================================== > > Nov 3 23:04:37 INOCESvmps1 vmpsd: VQP Request > > Nov 3 23:04:37 INOCESvmps1 vmpsd: Unknown: 1 > > Nov 3 23:04:37 INOCESvmps1 vmpsd: Request Type: 1 > > Nov 3 23:04:37 INOCESvmps1 vmpsd: Response: 0 > > Nov 3 23:04:37 INOCESvmps1 vmpsd: No. Data Items: 6 > > Nov 3 23:04:37 INOCESvmps1 vmpsd: Sequence No.: 4660 > > Nov 3 23:04:37 INOCESvmps1 vmpsd: Client IP address: 193.111.222.1 > > Nov 3 23:04:37 INOCESvmps1 vmpsd: Port name: Fa0/17 > > Nov 3 23:04:37 INOCESvmps1 vmpsd: Vlan name: test > > Nov 3 23:04:37 INOCESvmps1 vmpsd: Domain name: Domain > > Nov 3 23:04:37 INOCESvmps1 vmpsd: MAC address: 080020b0cb95 > > Nov 3 23:04:37 INOCESvmps1 vmpsd: >>>> Sending: Domain > > 193.111.222.1 Fa0/17 > > switch1 0800.20b0.cb95 > > > > My external sends back: "ALLOW test", but vmpsd never sees it > > arriving and > > vmpsd just sits there waiting. > > > > Any sugsestions /tips? > > > > Thanks, > > > > Sean > > > > > > > > > > ------------------------------------------------------- > > SF.Net email is sponsored by: > > Tame your development challenges with Apache's Geronimo App > > Server. Download > > it for free - -and be entered to win a 42" plasma tv or > your very own > > Sony(tm)PSP. Click here to play: > http://sourceforge.net/geronimo.php > > _______________________________________________ > > Vmps-devel mailing list > > Vmp...@li... > > https://lists.sourceforge.net/lists/listinfo/vmps-devel > > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by the JBoss Inc. Get Certified Today > Register for a JBoss Training Course. Free Certification Exam > for All Training Attendees Through End of 2005. For more info visit: > http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click > _______________________________________________ > Vmps-devel mailing list > Vmp...@li... > https://lists.sourceforge.net/lists/listinfo/vmps-devel > |