Zabbixを用いた位置情報の収集と管理～本編の没ネタ集～
NTTコムソリューションズ株式会社
マネジメントソリューション本部
プラットフォームソリューション部

田中 武信

自己紹介

https://www.zabicom.com

田中武信

マネジメントソリューション本部
プラットフォームソリューション部
1

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

Windows10で位置情報を取る

2

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

Windows10では位置情報が取れます

https://support.microsoft.com/ja-jp/help/4468240/windows-10-location-service-and-privacy

https://docs.microsoft.com/ja-jp/windows/uwp/maps-and-location/get-location
3

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

位置情報の取得許可

4

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

位置情報を取得するPowerShellを準備します
geo.ps1
Add-Type -AssemblyName System.Device #Required to access System.Device.Location namespace$GeoWatcher = New-Object System.Device.Location.GeoCoordinateWatcher #Create the required object$GeoWatcher.Start() #Begin resolving current locaton
while (($GeoWatcher.Status -ne 'Ready') -and ($GeoWatcher.Permission -ne 'Denied')) {Start-Sleep -Milliseconds 100 #Wait for discovery.
}
if ($GeoWatcher.Permission -eq 'Denied'){Write-Error 'Access Denied for Location Information'} else {$watcher = New-Object System.Device.Location.GeoCoordinateWatcher$sourceId = "Location"$job = Register-ObjectEvent -InputObject $watcher -EventName PositionChanged -SourceIdentifier $sourceId$watcher.Start()$event = Wait-Event $sourceId$event.SourceEventArgs.Position.Location
Remove-Event $sourceId
Unregister-Event $sourceId}コピペしたコードなので自己責任で

5

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

バッチファイル経由で実行してログを吐かせますgeoinfo.bat@echo off
powershell -ExecutionPolicy RemoteSigned -File C:¥zabbix_agent¥bin¥geo.ps1 > C:¥zabbix_agent¥log¥geoinfo.txt

geoinfo.txt
LatitudeLongitude
Altitude
HorizontalAccuracy
VerticalAccuracy
Speed
CourseIsUnknown

6: 35.684: 139.8088:0: 79628
: NaN
: NaN
: NaN
: FalseCopyright © 2019 NTT Com Solutions Corporation. All rights reserved.

アイテムを設定しますPowerShellを実行するアイテム
テキストを読むアイテム
テキストの中身を分割する
依存アイテム

テキスト読み取り
アイテム

PowerShell実行
アイテム
geoinfo.txt

geoinfo.bat
geo.ps1
7

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

緯度アイテム
経度アイテム高度アイテムこんな感じで位置情報が格納されます

8

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

Linuxで位置情報を取る

9Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

GPS受信機を買います

10

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

GPSレシーバー + Raspberry Pi Zero + モバイルバッテリー¥4,380

priceless¥1,320 + α

11Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

gpsdから情報を取ります
gpsinfo.py#!/usr/bin/python3
from gps3 import gps3
import codecs
gps_socket = gps3.GPSDSocket()
data_stream = gps3.DataStream()
gps_socket.connect()gps_socket.watch()

コピペしたコードなので自己責任で

for new_data in gps_socket:
if new_data:
data_stream.unpack(new_data)
print('time : ', data_stream.TPV['time'], file=codecs.open('/temp/geoinfo.log', 'a', 'utf-8'))
print('lat : ', data_stream.TPV['lat'], file=codecs.open('/temp/geoinfo.log', 'a', 'utf-8'))
print('lon : ', data_stream.TPV['lon'], file=codecs.open('/temp/geoinfo.log', 'a', 'utf-8'))
print('alt : ', data_stream.TPV['alt'], file=codecs.open('/temp/geoinfo.log', 'a', 'utf-8'))
print('speed : ', data_stream.TPV['speed'], file=codecs.open('/temp/geoinfo.log', 'a', 'utf-8'))

12Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

出力結果を加工します
gpsinfo.pyの出力
time : 2019-11-14T17:16:13.000Z
lat : 35.682090852
lon : 139.631124968
alt : 61.938
speed : 0.0
time : 2019-11-14T17:16:14.000Z
lat : 35.682090852
lon : 139.631124968
alt : 61.938
speed : 0.0
time : 2019-11-14T17:16:15.000Z
lat : 35.682090852
lon : 139.631124968
alt : 61.938
speed : 0.0
time : 2019-11-14T17:16:16.000Z
lat : 35.682090852
lon : 139.631124968
alt : 61.938
speed : 0.0
13

1回分に整形
Date: 2019/11/15 02:16:18
Latitude: 35.682090852
Longitude : 139.631124968
Altitude: 61.938
IsUnknown : False

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

アイテムを設定します
テキストを読むアイテム
テキストの中身を分割する
依存アイテム

テキスト読み取り
アイテム

cron

緯度アイテムgpsinfo.py
geoinfo.txt
14

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

経度アイテム高度アイテムこんな感じで位置情報が格納されます

15

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

位置情報の活用

16

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

Google Mapにピンを立てる

17

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

Google Mapを呼び出すページ<script type="text/javascript">function initialize() {// Google Mapで利用する初期設定用の変数
var latlng = new google.maps.LatLng(35.6821956096214, 139.631341822975);
var mapOptions = {zoom: 9,mapTypeId: google.maps.MapTypeId.ROADMAP,center: latlng};// GoogleMapの生成
var gmap = new google.maps.Map(document.getElementById("map"), mapOptions);
var markerData = [{ lat:"35.6824863333333", lng:"139.631027333333", title:"TABLET02", os:"WindowsTABLET0MicrosoftWindows10Homex86" },{ lat:"35.682351", lng:"139.631304", title:"DESKTOP-A1CJC3R", os:"WindowsDESKTOPMicrosoftWindows10Homex64" },{ lat:"35.682074454", lng:"139.631091716", title:"gps-pizero-01", os:"RaspbianGNU/Linux10(buster)" },];for (i = 0;i < markerData.length;i++) {var marker = new google.maps.Marker({position: new google.maps.LatLng(markerData[i].lat, markerData[i].lng),
title: markerData[i].title});marker.setMap(gmap);}}</script></head><body onload="initialize()"><div id="map" style="width: 1000px; height: 600px;"></div>

18

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

Google Mapに経路を表示する

19

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

Google Mapに読み込ませるKML<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Document><name>2013_aug26_toyara.kml</name><Style id="line-A52714-4000-nodesc-normal">~中略~<Placemark><name>Tokyo</name><styleUrl>#line-A52714-4000-nodesc</styleUrl><LineString><tessellate>1</tessellate><coordinates>
139.630905,35.682021,0139.630936,35.682013,0139.630952,35.682013,0139.630939,35.682013,0139.630979,35.682013,0139.630958,35.682013,0139.630908,35.682013,0~以下略~

https://developers.google.com/kml/documentation/kml_tut?hl=ja
20

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

3Dマップに書いてみる
4DVIZ®（4D可視化ソリューション）

https://www.nttcom.co.jp/4dv/
21

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

経路＋時間22

Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.

ご清聴ありがとうございました23Copyright © 2019 NTT Com Solutions Corporation. All rights reserved.