The given configuration is invalid. Reason: undefined method `-' for nil:NilClass

Hi,

I am receiving the below error and am not sure what is causing it. I am just trying to convert eastings and northings to co-ordinates to make the data useful in kibana. Anyone know what could be causing it?

[2019-07-09T10:10:56,026][FATAL][logstash.runner ] The given configuration is invalid. Reason: undefined method `-' for nil:NilClass
[2019-07-09T10:10:56,037][ERROR][org.logstash.Logstash ] java.lang.IllegalStateException: Logstash stopped processing because of an error: (SystemExit) exit

In ruby file:

def filter(event)

	#metres in, degrees out
	east = event.get("easting")
	north = event.get("northing")
	
	if east == nil
		event.set("location", "nil, nil") #latitude & longitude respectively
		return [event]
	else
	
		k = 0.9996012717 #grid scale factor on central meridean
		origin_lat = 49.0
		origin_long = -2.0    
		origin_x = 400000 # 400 kM
		origin_y = -100000 # 100 kM
		a = 6377563.396 # Airy Spheroid
		b = 6356256.910

		# compute interim values
		a = a * k
		b = b * k
                
		n1 = (a - b)/(a + b)
		n2 = n1 * n1
		n3 = n2 * n1   
                                                                                
		lat = origin_lat * Math::PI / 180.0 # to radians                                                    
                
		e2 = (a * a - b * b)/(a * a)  # first eccentricity
		#ex = (a * a - b * b)/(b * b)  # second eccentricity

		origin_northings = b * lat + b * (n1 * (1.0 + 5.0 * n1*(1.0+n1)/4.0)*lat - 3.0*n1*(1.0+n1*(1.0+7.0*n1/8.0))*Math.sin(lat)*Math.cos(lat) + (15.0*n1*(n1+n2)/8.0)*Math.sin(2.0*lat)*Math.cos(2.0*lat) - (35.0*n3/24.0)*Math.sin(3.0*lat)*Math.cos(3.0*lat) )

		northing = north - origin_y 
		easting = east - origin_x

		# Evaluate M term: latitude of the northing on the centre meridian

		northing += origin_northings  
           
		phid = northing / (b*(1.0 + n1 + 5.0*(n2+n3)/4.0)) - 1.0
		phid2 = phid + 1.0                                

		while (phid2 - phid).abs > 1E-6
   
			phid = phid2
			nphid = b*phid + b*(n1*(1.0 + 5.0*n1*(1.0+n1)/4.0)*phid - 3.0*n1*(1.0+n1*(1.0+7.0*n1/8.0))*Math.sin(phid)*Math.cos(phid) + (15.0*n1*(n1+n2)/8.0)*Math.sin(2.0*phid)*Math.cos(2.0*phid) - (35.0*n3/24.0)*Math.sin(3.0*phid)*Math.cos(3.0*phid) )
           
			dnphid = b*((1.0+n1+5.0*(n2+n3)/4.0) - 3.0*(n1+n2+7.0*n3/8.0)*Math.cos(2.0*phid) + (15.0*(n2+n3)/4.0)*Math.cos(4*phid) - (35.0*n3/8.0)*Math.cos(6.0*phid))
           
			phid2 = phid - (nphid - northing)/dnphid
		end

		c  = Math.cos(phid)
		s  = Math.sin(phid)
		t  = Math.tan(phid)
		t2 = t*t
		q2 = easting*easting


		nu2 = (a*a)/(1.0 - e2*s*s)
		nu = Math.sqrt(nu2)

		nudivrho = a*a*c*c/(b*b) - c*c + 1.0

		eta2 = nudivrho - 1

		rho = nu / nudivrho

		invnurho = ((1.0 - e2*s*s)*(1.0 - e2*s*s))/(a*a*(1.0 - e2))

		lat = phid - t*q2*invnurho/2.0 + (q2*q2*(t/(24*rho*nu2*nu)*(5 + (3*t2) + eta2 - (9*t2*eta2))))

		lon = (easting/(c*nu)) - (easting*q2*((nudivrho+2.0*t2)/(6.0*nu2))/(c*nu)) + (q2*q2*easting*(5 + (28*t2) + (24*t2*t2))/(120*nu2*nu2*nu*c))
	
		latitude = lat * 180.0 / Math::PI
		longitude = (lon * 180.0 / Math::PI) + origin_long
		#location = "#{latitude}, #{longitude}"
	
		event.set("location", "#{latitude}, #{longitude}") #latitude & longitude respectively
	
		return [event]
	end

end

test "north east" do

  in_event { [{"easting" => 614502} ,  {"northing" => 246928}] }

  expect("returns location") do |events|
	events.get("location") == "52.07867241905442, 1.1307201995107992"
	
  end
end

In config file:

input {
# sql query 1, 2, 3, 4, 5, 7, 8, 9 gets the response times by product id, domain id, cp id,
  jdbc {
  jdbc_driver_library => ""
  jdbc_connection_string => ""
  jdbc_driver_class => ""
  jdbc_user => ""
	jdbc_password => ""
  last_run_metadata_path => ""
  statement => "SELECT v_product_id, v_domain_id, v_comm_provider_id, i_status, v_api_name,
	v_managed_server,d_updated_date, nvl(i_time_taken,0) resp_time, v_reservation_ref, cp_name, v_description, 
	v_error_desc, CONCAT(CONCAT(i_status, ': '),v_error_desc) code_and_desc, northing, easting
	FROM OR_FieldReserve.tb_fr_track_performance a
	LEFT OUTER JOIN OR_FieldReserve.TB_CP_DETAILS b ON a.v_comm_provider_id = b.cp_id
	LEFT OUTER JOIN OR_FieldReserve.TB_AREA c ON a.v_domain_id = c.v_area_id
	LEFT OUTER JOIN OR_FieldReserve.TB_FR_ERROR_CODES_ASG d ON a.i_status = d.i_error_code
	LEFT OUTER JOIN OR_FieldReserve.Pwa_exchange_map e ON a.v_exchange_id = e.v_arms_gc
	WHERE d_updated_date > :sql_last_value"
  #use_column_value => true
  #tracking_column => "d_updated_date"
  schedule => "*/2 * * * *"
  }
}

filter{
	ruby{		
		path => "/software/bea/elk/logstash-7.1.1/config/NEtoLL.rb"		
	}
}

output {
	stdout { codec => rubydebug }
  elasticsearch {
    hosts => [""]
    index => ""
    user => ""
    password => ""
  }
}

All solved, there was an issue with the test (still unresolved), but the filter wasn't working as the eastings and northings were set as strings.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.