shinken-monitoring/mod-ndodb-mysql — pull request #7 by jccomputing (2014-09-09 15:22:10+00:00)
Title: Escape backslash characters to avoid invalid SQL queries

Sometimes there are backslashes in the perfdata returned by a plugin. For example, see the returned data of NSClient++ CheckDriveSize:
```'C:\ %'=6%;10;5 'C:\'=37.438G;3.96899;1.985;0;39.691 'D:\ %'=90%;10;5 'D:\'=8.22G;8;4;0;79.997```

This causes programming error exceptions:
```
2014-09-09 16:13:01,386 [1410271981] Warning : [broker-master] [MysqlDB] A query raised a programming error: UPDATE nagios_servicestatus set check_type='0' , execution_time='0.324510097504' , current_state='0' , last_check='2014-09-09 16:12:58' , state_type='1' , perfdata='''C:\ %''=65%;10;5 ''C:\''=13.973G;3.907;1.953;0;39.067 ''D:\ %''=34%;10;5 ''D:\''=6766.371M;1023.67;511.835;0;10236.699' , latency='0.583251953125' , current_check_attempt='1' , percent_state_change='0.0' , instance_id='2' , long_output='' , output='OK: All drives within bounds.' WHERE service_object_id='3491' , (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'G;3.907;1.953;0;39.067 ''D:\\ %''=34%;10;5 ''D:\\''=6766.371M;1023.67;511.835;0;10' at line 1")
```

This patch escapes backslashes in perfdata when constructing the SQL queries.

I don't know if it's a proper fix or if other fields should be escaped, but at least it fixes these errors.