Пример #1
0
static PyObject *
python_pfget_time( PyObject *self, PyObject *args ) {
	char	*usage = "Usage: _stock._pfget_time( pfname, pfkey )\n";
	char	*pfname;
	char	*pfkey;
	double	pfvalue;
	char	errmsg[STRSZ];
	Pf	*pf;

	if( ! PyArg_ParseTuple( args, "ss", &pfname, &pfkey ) ) {

		USAGE;

		return NULL;
	}

	if( ( pf = getPf( pfname ) ) == (Pf *) NULL ) {
		
		sprintf( errmsg, "Failure opening parameter file '%s'\n", pfname );

		raise_elog( ELOG_COMPLAIN, errmsg );

		return NULL;
	}

	pfvalue = pfget_time( pf, pfkey );

	return Py_BuildValue( "d", pfvalue );
}
Пример #2
0
static Pf *
orbconnections2pf( Pf *pfanalyze )
{
	Pf	*pf;
	Pf	*pfserver;
	Pf	*pfconnections;
	Pf	*pfclients;
	Pf	*pfclient;
	Pf	*pfconnection;
	Tbl	*client_keys;
	int	ikey;
	char	*client_key;
	char	*clientid;
	char	*what;
	char	*perm;
	char	*clientaddress;
	char	*serveraddress;
	char	clientaddress_ipc[STRSZ];
	char	serveraddress_ipc[STRSZ];
	int	serverport;
	double	atime;
	regex_t	preg_findclient;
	char	closeorb[STRSZ];
	char	o2omachine[STRSZ];
	char	farorb[STRSZ];
	int	closeport;
	int	farport;
	char	orbstat_machine_hostname[STRSZ];
	char	orbstat_machine_ipc[STRSZ];
	int	orbstat_machine_ip;
	char	cmdline_fromorb[STRSZ];
	char	cmdline_toorb[STRSZ];
	char	cmdline_fromip[STRSZ];
	char	cmdline_fromipc[STRSZ];
	char	cmdline_toip[STRSZ];
	char	cmdline_toipc[STRSZ];
	char	formal_name[STRSZ];
	int	formal_count = 0;
	int	cmdline_fromport;
	int	cmdline_toport;
	struct in_addr addr;
	
	regcomp( &preg_findclient, "^orb2orb ", 0 );

	pf = pfnew( PFFILE );

	atime = pfget_time( pfanalyze, "client_when" );
	pfput_time( pf, "connections_when", atime );

	my_ip( orbstat_machine_hostname, 
	       orbstat_machine_ipc, 
	       &orbstat_machine_ip );

	if( is_localhost( orbstat_machine_ipc ) ) {
		
		elog_complain( 0, "libpforbstat: orbstat machine is localhost; giving up on connection analysis\n" );
		regfree( &preg_findclient );
		return pf;

	} else {

		pfput_string( pf, "orbstat_machine", orbstat_machine_ipc );
	}

	pfget( pfanalyze, "server", (void **) &pfserver );
	serveraddress = pfget_string( pfserver, "address" );
	serverport = pfget_int( pfserver, "port" );

	if( is_nonroutable( serveraddress ) && 
	    report_nonroutable( serveraddress ) ) {

		elog_complain( 0, "libpforbstat: warning: monitored server %s is nonroutable\n", serveraddress );
	}
	
	if( name2ip( serveraddress, &addr, serveraddress_ipc ) < 0 ) {
		
		elog_complain( 0, "libpforbstat: warning: name translation failed for %s\n", serveraddress );
		strcpy( serveraddress_ipc, serveraddress );
	}

	if( is_localhost( serveraddress ) ) {

		strcpy( closeorb, orbstat_machine_ipc );

	} else {

		strcpy( closeorb, serveraddress_ipc );
	}

	closeport = serverport;

	/* SCAFFOLD: this causes memory problems. Leave untranslated for now:
	pfput_string( pfserver, "address", closeorb ); Record the translated server address */

	pfget( pfanalyze, "clients", (void **) &pfclients );

	client_keys = pfkeys( pfclients );

	pfconnections = pfnew( PFTBL );

	for( ikey = 0; ikey < maxtbl( client_keys ); ikey++ ) {

		client_key = gettbl( client_keys, ikey );
		pfget( pfclients, client_key, (void **) &pfclient );

		what = pfget_string( pfclient, "what" );

		if( ! regexec( &preg_findclient, what, 0, 0, 0 ) ) {

			pfconnection = pfnew( PFARR );

			/* Easy things: */

			pfput_string( pfconnection, "what", what );

			if( ( clientid = pfget_string( pfclient, "clientid") ) != NULL ) {

				pfput_string( pfconnection, "clientid", clientid );
			}
			
			/* Preparatory raw-information acquisition: */

			extract_orb2orb_orbargs( what, 
						 cmdline_fromorb, 
						 cmdline_toorb );

			parse_orbname( cmdline_fromorb, 
				       cmdline_fromip, 
				       &cmdline_fromport );

			if( name2ip( cmdline_fromip, &addr, cmdline_fromipc ) < 0 ) {
		
				elog_complain( 0, 
					"libpforbstat: warning: name translation failed for %s\n", cmdline_fromipc );
				strcpy( cmdline_fromipc, cmdline_fromip );
			}

			parse_orbname( cmdline_toorb, 
				       cmdline_toip, 
				       &cmdline_toport );

			if( name2ip( cmdline_toip, &addr, cmdline_toipc ) < 0 ) {
		
				elog_complain( 0, 
					"libpforbstat: warning: name translation failed for %s\n", cmdline_toipc );
				strcpy( cmdline_toipc, cmdline_toip );
			}

			perm = pfget_string( pfclient, "perm" );

			clientaddress = pfget_string( pfclient, "address" );

			if( name2ip( clientaddress, &addr, clientaddress_ipc ) < 0 ) {
		
				elog_complain( 0, 
					"libpforbstat: warning: name translation failed for %s\n", clientaddress );
				strcpy( clientaddress_ipc, clientaddress );
			}

			/* Analysis */

			if( is_nonroutable( clientaddress ) &&
			    report_nonroutable( clientaddress ) ) { 
				
				elog_complain( 0, "libpforbstat: warning: clientaddress %s is nonroutable\n", 
						clientaddress );
			} 
			
			if( is_localhost( clientaddress ) ) {
			
				strcpy( o2omachine, serveraddress_ipc );

			} else {
				
				strcpy( o2omachine, clientaddress_ipc );
			}

			pfput_string( pfconnection, "o2omachine", o2omachine );

			if( STREQ( perm, "w" ) ) {

				strcpy( farorb, cmdline_fromipc );
				farport = cmdline_fromport;

			} else if( STREQ( perm, "r" ) ) {		

				strcpy( farorb, cmdline_toipc );
				farport = cmdline_toport;

			} else {
				elog_complain( 0, 
						"libpforbstat: unexpected perm '%s' in client info; giving up on client\n", 
						perm );
				pffree( pfconnection );
				continue;
			}

			if(is_localhost(farorb)) {

				strcpy( farorb, o2omachine );
			}

			if( STREQ( perm, "w" ) ) {
			
				pfput_string( pfconnection, "fromaddress", farorb );
				pfput_int( pfconnection, "fromport", farport );

				pfput_string( pfconnection, "toaddress", closeorb );
				pfput_int( pfconnection, "toport", closeport );

				pfput_string( pfconnection, "closeorb", "toaddress" );

			} else {	/* perm == "r" */

				pfput_string( pfconnection, "fromaddress", closeorb );
				pfput_int( pfconnection, "fromport", closeport );

				pfput_string( pfconnection, "toaddress", farorb );
				pfput_int( pfconnection, "toport", farport );

				pfput_string( pfconnection, "closeorb", "fromaddress" );
			} 	

			sprintf( formal_name, "client%03d", ++formal_count );
			pfput( pfconnections, formal_name, pfconnection, PFPF );
		}
	}

	pfput( pf, "connections", pfconnections, PFPF );

	regfree( &preg_findclient );

	return pf;
}
Пример #3
0
static Pf *
orbdatabases2pf( Pf *pfanalyze ) 
{
	Pf	*pf;
	Pf	*pfdatabases;
	Pf	*pfdatabase;
	Pf	*pfclients;
	Pf	*pfclient;
	double	atime;
	Tbl	*client_keys;
	int	ikey;
	char	*client_key;
	char	*what;
	char	*serverhost;
	char	*clientid;
	char	*clientaddress;
	char	*serveraddress;
	char	*serverport;
	char	dbprogram[STRSZ];
	char	dbpath[STRSZ];
	char	dir[STRSZ];
	char	dfile[STRSZ];
	char	formal_name[STRSZ];
	int	formal_count = 0;
	char	*delim = ":";
	char	*hostdir;
	char	*serverhostcopy;
	char	*abspath;

	pf = pfnew( PFFILE );

	pfdatabases = pfnew( PFTBL );

	atime = pfget_time( pfanalyze, "client_when" );
	pfput_time( pf, "databases_when", atime );

	pfeval( pfanalyze, "server{address}", &serveraddress );
	pfeval( pfanalyze, "server{port}", &serverport );
	pfeval( pfanalyze, "server{host}", &serverhost );

	serverhostcopy = strdup( serverhost );
	strtok_r( serverhostcopy, delim, &hostdir );

	pfget( pfanalyze, "clients", (void **) &pfclients );

	client_keys = pfkeys( pfclients );

	for( ikey = 0; ikey < maxtbl( client_keys ); ikey++ ) {

		client_key = gettbl( client_keys, ikey );
		pfget( pfclients, client_key, (void **) &pfclient );

		what = pfget_string( pfclient, "what" );
		clientaddress = pfget_string( pfclient, "address" );
		clientid = pfget_string( pfclient, "clientid" );

		if( is_dbprogram( what, dbprogram, dbpath ) ) {

			pfdatabase = pfnew( PFARR );

			pfput_string( pfdatabase, "clientid", clientid );
			pfput_string( pfdatabase, "serveraddress", serveraddress );
			pfput_string( pfdatabase, "serverport", serverport );
			pfput_string( pfdatabase, "dbprogram", dbprogram );

			if( is_localhost( clientaddress ) ) {

				pfput_string( pfdatabase, "dbmachine", serveraddress );

				abspath = concatpaths( hostdir, dbpath, 0 );
				parsepath( abspath, dir, dfile, 0 );
				free( abspath );

			} else {

				pfput_string( pfdatabase, "dbmachine", clientaddress );

				abspath = concatpaths( "", dbpath, 0 );
				parsepath( abspath, dir, dfile, 0 );
				free( abspath );
			}

			pfput_string( pfdatabase, "dir", dir );
			pfput_string( pfdatabase, "dfile", dfile );

			sprintf( formal_name, "client%03d", ++formal_count );
			pfput( pfdatabases, formal_name, pfdatabase, PFPF );
		}
	}

	free( serverhostcopy );

	pfput( pf, "databases", pfdatabases, PFPF );

	return pf;
}